OPTIM = -O3 -funroll-loops ;
# Headers rep
-HDRS = . core core/i386 decoder encoder ;
+HDRS = . common common/i386 decoder encoder ;
-SOURCES_C = core/mc.c core/predict.c core/pixel.c core/macroblock.c
- core/frame.c core/dct.c core/cpu.c core/cabac.c
- core/common.c core/mdate.c core/csp.c
+SOURCES_C = common/mc.c common/predict.c common/pixel.c common/macroblock.c
+ common/frame.c common/dct.c common/cpu.c common/cabac.c
+ common/common.c common/mdate.c common/csp.c
encoder/analyse.c encoder/me.c encoder/ratecontrol.c
encoder/set.c encoder/macroblock.c encoder/cabac.c encoder/cavlc.c
encoder/encoder.c encoder/eval.c ;
-SOURCES_X86 = core/i386/cpu.asm ;
-SOURCES_MMX = core/i386/mc-c.c core/i386/dct-c.c core/i386/predict.c core/i386/dct.asm core/i386/pixel.asm core/i386/mc.asm ;
+SOURCES_X86 = common/i386/cpu.asm ;
+SOURCES_MMX = common/i386/mc-c.c common/i386/dct-c.c common/i386/predict.c common/i386/dct.asm common/i386/pixel.asm common/i386/mc.asm ;
-SOURCES_ALTIVEC = core/ppc/mc.c core/ppc/pixel.c ;
+SOURCES_ALTIVEC = common/ppc/mc.c common/ppc/pixel.c ;
# libx264
SOURCES_X264 = $(SOURCES_C) ;
# Uncomment this for Mac OS X
#SYS_MACOSX=1
-SRCS_COMMON= core/mc.c core/predict.c core/pixel.c core/macroblock.c \
- core/frame.c core/dct.c core/cpu.c core/cabac.c \
- core/common.c core/mdate.c core/csp.c \
+SRCS_COMMON= common/mc.c common/predict.c common/pixel.c common/macroblock.c \
+ common/frame.c common/dct.c common/cpu.c common/cabac.c \
+ common/common.c common/mdate.c common/csp.c \
encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
encoder/set.c encoder/macroblock.c encoder/cabac.c \
encoder/cavlc.c encoder/encoder.c encoder/eval.c x264.c
ifdef SYS_MACOSX
PFLAGS=-DARCH_PPC -DSYS_MACOSX -faltivec
-SRCS= $(SRCS_COMMON) core/ppc/mc.c core/ppc/pixel.c
+SRCS= $(SRCS_COMMON) common/ppc/mc.c common/ppc/pixel.c
else
PFLAGS=-DARCH_X86 -DHAVE_MMXEXT -DHAVE_SSE2 -DHAVE_MALLOC_H
-SRCS= $(SRCS_COMMON) core/i386/mc-c.c core/i386/dct-c.c core/i386/predict.c
-ASMSRC= core/i386/dct.asm core/i386/cpu.asm core/i386/pixel.asm core/i386/mc.asm
+SRCS= $(SRCS_COMMON) common/i386/mc-c.c common/i386/dct-c.c common/i386/predict.c
+ASMSRC= common/i386/dct.asm common/i386/cpu.asm common/i386/pixel.asm common/i386/mc.asm
OBJASM= $(ASMSRC:%.asm=%.o)
endif
CC=gcc
CFLAGS=-g -Wall -I. -mno-cygwin -DDEBUG -O4 -funroll-loops -D__X264__ -UHAVE_MALLOC_H $(PFLAGS)
-SRCS= core/mc.c core/predict.c core/pixel.c core/macroblock.c \
- core/frame.c core/dct.c core/cpu.c core/cabac.c \
- core/common.c core/mdate.c core/csp.c \
+SRCS= common/mc.c common/predict.c common/pixel.c common/macroblock.c \
+ common/frame.c common/dct.c common/cpu.c common/cabac.c \
+ common/common.c common/mdate.c common/csp.c \
encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
encoder/set.c encoder/macroblock.c encoder/cabac.c encoder/cavlc.c \
encoder/encoder.c \
- core/i386/mc-c.c core/i386/dct-c.c core/i386/predict.c \
+ common/i386/mc-c.c common/i386/dct-c.c common/i386/predict.c \
x264.c
AS= nasm
#for cygwin
ASFLAGS=-f win32 -DPREFIX $(PFLAGS)
-ASMSRC= core/i386/dct.asm core/i386/cpu.asm core/i386/pixel.asm core/i386/mc.asm
+ASMSRC= common/i386/dct.asm common/i386/cpu.asm common/i386/pixel.asm common/i386/mc.asm
OBJASM= $(ASMSRC:%.asm=%.o)
OBJS = $(SRCS:%.c=%.o)
DIR_SRC=$(DIR_CUR)/../..
# Sources
-SRC_C= core/mc.c core/predict.c core/pixel.c core/macroblock.c \
- core/frame.c core/dct.c core/cpu.c core/cabac.c \
- core/common.c core/mdate.c core/csp.c \
+SRC_C= common/mc.c common/predict.c common/pixel.c common/macroblock.c \
+ common/frame.c common/dct.c common/cpu.c common/cabac.c \
+ common/common.c common/mdate.c common/csp.c \
encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
encoder/set.c encoder/macroblock.c encoder/cabac.c encoder/cavlc.c \
encoder/encoder.c encoder/eval.c \
- core/i386/mc-c.c core/i386/dct-c.c core/i386/predict.c
+ common/i386/mc-c.c common/i386/dct-c.c common/i386/predict.c
-SRC_ASM= core/i386/dct.asm core/i386/cpu.asm core/i386/pixel.asm core/i386/mc.asm
+SRC_ASM= common/i386/dct.asm common/i386/cpu.asm common/i386/pixel.asm common/i386/mc.asm
# Alias
RM= rm -rf
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "./core" /I "./encode" /I "./decode" /I "../../extras" /I "../.." /D "NDEBUG" /D "_LIB" /D "WIN32" /D "_MBCS" /D "__X264__" /D "HAVE_MMXEXT" /D "ARCH_X86" /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "./common" /I "./encode" /I "./decode" /I "../../extras" /I "../.." /D "NDEBUG" /D "_LIB" /D "WIN32" /D "_MBCS" /D "__X264__" /D "HAVE_MMXEXT" /D "ARCH_X86" /FD /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x804 /d "NDEBUG"
# ADD RSC /l 0x804 /d "NDEBUG"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "./core" /I "./encode" /I "./decode" /I "../../extras" /I "../.." /D "_DEBUG" /D "_LIB" /D "WIN32" /D "_MBCS" /D "__X264__" /D "HAVE_MMXEXT" /D "ARCH_X86" /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "./common" /I "./encode" /I "./decode" /I "../../extras" /I "../.." /D "_DEBUG" /D "_LIB" /D "WIN32" /D "_MBCS" /D "__X264__" /D "HAVE_MMXEXT" /D "ARCH_X86" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x804 /d "_DEBUG"
# ADD RSC /l 0x804 /d "_DEBUG"
# PROP Default_Filter ".h"
# Begin Source File
-SOURCE=..\..\core\bs.h
+SOURCE=..\..\common\bs.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\cabac.h
+SOURCE=..\..\common\cabac.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\clip1.h
+SOURCE=..\..\common\clip1.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\common.h
+SOURCE=..\..\common\common.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\cpu.h
+SOURCE=..\..\common\cpu.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\csp.h
+SOURCE=..\..\common\csp.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\dct.h
+SOURCE=..\..\common\dct.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\frame.h
+SOURCE=..\..\common\frame.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\macroblock.h
+SOURCE=..\..\common\macroblock.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\mc.h
+SOURCE=..\..\common\mc.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\pixel.h
+SOURCE=..\..\common\pixel.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\predict.h
+SOURCE=..\..\common\predict.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\set.h
+SOURCE=..\..\common\set.h
# End Source File
# Begin Source File
-SOURCE=..\..\core\vlc.h
+SOURCE=..\..\common\vlc.h
# End Source File
# End Group
# Begin Group "I386"
# PROP Default_Filter "*.h,*.c,*.asm"
# Begin Source File
-SOURCE=..\..\core\i386\cpu.asm
+SOURCE=..\..\common\i386\cpu.asm
!IF "$(CFG)" == "libx264 - Win32 Release"
# Begin Custom Build - Assembly $(InputPath)
IntDir=.\Release
-InputPath=..\..\core\i386\cpu.asm
+InputPath=..\..\common\i386\cpu.asm
InputName=cpu
"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# Begin Custom Build - Assembly $(InputPath)
IntDir=.\Debug
-InputPath=..\..\core\i386\cpu.asm
+InputPath=..\..\common\i386\cpu.asm
InputName=cpu
"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# End Source File
# Begin Source File
-SOURCE="..\..\core\i386\dct-c.c"
+SOURCE="..\..\common\i386\dct-c.c"
# End Source File
# Begin Source File
-SOURCE=..\..\core\i386\dct.asm
+SOURCE=..\..\common\i386\dct.asm
!IF "$(CFG)" == "libx264 - Win32 Release"
# Begin Custom Build - Assembly $(InputPath)
IntDir=.\Release
-InputPath=..\..\core\i386\dct.asm
+InputPath=..\..\common\i386\dct.asm
InputName=dct
"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# Begin Custom Build - Assembly $(InputPath)
IntDir=.\Debug
-InputPath=..\..\core\i386\dct.asm
+InputPath=..\..\common\i386\dct.asm
InputName=dct
"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# End Source File
# Begin Source File
-SOURCE=..\..\core\i386\dct.h
+SOURCE=..\..\common\i386\dct.h
# End Source File
# Begin Source File
-SOURCE="..\..\core\i386\mc-c.c"
+SOURCE="..\..\common\i386\mc-c.c"
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\i386\mc.asm
+SOURCE=..\..\common\i386\mc.asm
!IF "$(CFG)" == "libx264 - Win32 Release"
# Begin Custom Build - Assembly $(InputPath)
IntDir=.\Release
-InputPath=..\..\core\i386\mc.asm
+InputPath=..\..\common\i386\mc.asm
InputName=mc
"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# Begin Custom Build - Assembly $(InputPath)
IntDir=.\Debug
-InputPath=..\..\core\i386\mc.asm
+InputPath=..\..\common\i386\mc.asm
InputName=mc
"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# End Source File
# Begin Source File
-SOURCE=..\..\core\i386\pixel.asm
+SOURCE=..\..\common\i386\pixel.asm
!IF "$(CFG)" == "libx264 - Win32 Release"
# Begin Custom Build - Assembly $(InputPath)
IntDir=.\Release
-InputPath=..\..\core\i386\pixel.asm
+InputPath=..\..\common\i386\pixel.asm
InputName=pixel
"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# Begin Custom Build - Assembly $(InputPath)
IntDir=.\Debug
-InputPath=..\..\core\i386\pixel.asm
+InputPath=..\..\common\i386\pixel.asm
InputName=pixel
"$(IntDir)\$(InputName).obj" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# End Source File
# Begin Source File
-SOURCE=..\..\core\i386\pixel.h
+SOURCE=..\..\common\i386\pixel.h
# End Source File
# End Group
# Begin Source File
-SOURCE=..\..\core\cabac.c
+SOURCE=..\..\common\cabac.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\common.c
+SOURCE=..\..\common\common.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\cpu.c
+SOURCE=..\..\common\cpu.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\csp.c
+SOURCE=..\..\common\csp.c
# End Source File
# Begin Source File
-SOURCE=..\..\core\dct.c
+SOURCE=..\..\common\dct.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\frame.c
+SOURCE=..\..\common\frame.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\macroblock.c
+SOURCE=..\..\common\macroblock.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\mc.c
+SOURCE=..\..\common\mc.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\mdate.c
+SOURCE=..\..\common\mdate.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\pixel.c
+SOURCE=..\..\common\pixel.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# End Source File
# Begin Source File
-SOURCE=..\..\core\predict.c
+SOURCE=..\..\common\predict.c
!IF "$(CFG)" == "libx264 - Win32 Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "./core" /I "./encode" /I "./decode" /I "../../extras" /I "../.." /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "__X264__" /D "HAVE_MMXEXT" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "./common" /I "./encode" /I "./decode" /I "../../extras" /I "../.." /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "__X264__" /D "HAVE_MMXEXT" /YX /FD /c
# ADD BASE RSC /l 0x804 /d "NDEBUG"
# ADD RSC /l 0x804 /d "NDEBUG"
BSC32=bscmake.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "../../core" /I "../../encode" /I "../../decode" /I "../../extras" /I "../.." /D "_DEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "__X264__" /D "HAVE_MMXEXT" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "../../common" /I "../../encode" /I "../../decode" /I "../../extras" /I "../.." /D "_DEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "__X264__" /D "HAVE_MMXEXT" /YX /FD /GZ /c
# ADD BASE RSC /l 0x804 /d "_DEBUG"
# ADD RSC /l 0x804 /d "_DEBUG"
BSC32=bscmake.exe
--- /dev/null
+/*****************************************************************************
+ * bs.h :
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: bs.h,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifdef _BS_H
+#warning FIXME Multiple inclusion of bs.h
+#else
+#define _BS_H
+
+typedef struct bs_s
+{
+ uint8_t *p_start;
+ uint8_t *p;
+ uint8_t *p_end;
+
+ int i_left; /* i_count number of available bits */
+} bs_t;
+
+static inline void bs_init( bs_t *s, void *p_data, int i_data )
+{
+ s->p_start = p_data;
+ s->p = p_data;
+ s->p_end = s->p + i_data;
+ s->i_left = 8;
+}
+static inline int bs_pos( bs_t *s )
+{
+ return( 8 * ( s->p - s->p_start ) + 8 - s->i_left );
+}
+static inline int bs_eof( bs_t *s )
+{
+ return( s->p >= s->p_end ? 1: 0 );
+}
+static inline uint32_t bs_read( bs_t *s, int i_count )
+{
+ static uint32_t i_mask[33] ={0x00,
+ 0x01, 0x03, 0x07, 0x0f,
+ 0x1f, 0x3f, 0x7f, 0xff,
+ 0x1ff, 0x3ff, 0x7ff, 0xfff,
+ 0x1fff, 0x3fff, 0x7fff, 0xffff,
+ 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff,
+ 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff,
+ 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff,
+ 0x1fffffff,0x3fffffff,0x7fffffff,0xffffffff};
+ int i_shr;
+ uint32_t i_result = 0;
+
+ while( i_count > 0 )
+ {
+ if( s->p >= s->p_end )
+ {
+ break;
+ }
+
+ if( ( i_shr = s->i_left - i_count ) >= 0 )
+ {
+ /* more in the buffer than requested */
+ i_result |= ( *s->p >> i_shr )&i_mask[i_count];
+ s->i_left -= i_count;
+ if( s->i_left == 0 )
+ {
+ s->p++;
+ s->i_left = 8;
+ }
+ return( i_result );
+ }
+ else
+ {
+ /* less in the buffer than requested */
+ i_result |= (*s->p&i_mask[s->i_left]) << -i_shr;
+ i_count -= s->i_left;
+ s->p++;
+ s->i_left = 8;
+ }
+ }
+
+ return( i_result );
+}
+
+#if 0
+/* Only > i386 */
+static uint32_t bswap32( uint32_t x )
+{
+ asm( "bswap %0": "=r" (x):"0" (x));
+ return x;
+}
+/* work only for i_count <= 32 - 7 */
+static inline uint32_t bs_read( bs_t *s, int i_count )
+{
+ if( s->p < s->p_end && i_count > 0 )
+ {
+#if 0
+ uint32_t i_cache = ((s->p[0] << 24)+(s->p[1] << 16)+(s->p[2] << 8)+s->p[3]) << (8-s->i_left);
+#else
+ uint32_t i_cache = bswap32( *((uint32_t*)s->p) ) << (8-s->i_left);
+#endif
+ uint32_t i_ret = i_cache >> ( 32 - i_count);
+
+ s->i_left -= i_count;
+#if 0
+ if( s->i_left <= 0 )
+ {
+ int i_skip = (8-s->i_left) >> 3;
+
+ s->p += i_skip;
+
+ s->i_left += i_skip << 3;
+ }
+#else
+ while( s->i_left <= 0 )
+ {
+ s->p++;
+ s->i_left += 8;
+ }
+#endif
+ return i_ret;
+ }
+ return 0;
+}
+
+#endif
+static inline uint32_t bs_read1( bs_t *s )
+{
+
+ if( s->p < s->p_end )
+ {
+ unsigned int i_result;
+
+ s->i_left--;
+ i_result = ( *s->p >> s->i_left )&0x01;
+ if( s->i_left == 0 )
+ {
+ s->p++;
+ s->i_left = 8;
+ }
+ return i_result;
+ }
+
+ return 0;
+}
+static inline uint32_t bs_show( bs_t *s, int i_count )
+{
+#if 0
+ bs_t s_tmp = *s;
+ return bs_read( &s_tmp, i_count );
+#else
+ if( s->p < s->p_end && i_count > 0 )
+ {
+ uint32_t i_cache = ((s->p[0] << 24)+(s->p[1] << 16)+(s->p[2] << 8)+s->p[3]) << (8-s->i_left);
+ return( i_cache >> ( 32 - i_count) );
+ }
+ return 0;
+#endif
+}
+
+/* TODO optimize */
+static inline void bs_skip( bs_t *s, int i_count )
+{
+ s->i_left -= i_count;
+
+ while( s->i_left <= 0 )
+ {
+ s->p++;
+ s->i_left += 8;
+ }
+}
+
+
+static inline int bs_read_ue( bs_t *s )
+{
+ int i = 0;
+
+ while( bs_read1( s ) == 0 && s->p < s->p_end && i < 32 )
+ {
+ i++;
+ }
+ return( ( 1 << i) - 1 + bs_read( s, i ) );
+}
+static inline int bs_read_se( bs_t *s )
+{
+ int val = bs_read_ue( s );
+
+ return val&0x01 ? (val+1)/2 : -(val/2);
+}
+
+static inline int bs_read_te( bs_t *s, int x )
+{
+ if( x == 1 )
+ {
+ return 1 - bs_read1( s );
+ }
+ else if( x > 1 )
+ {
+ return bs_read_ue( s );
+ }
+ return 0;
+}
+
+/* TODO optimize (write x bits at once) */
+static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits )
+{
+ while( i_count > 0 )
+ {
+ if( s->p >= s->p_end )
+ {
+ break;
+ }
+
+ i_count--;
+
+ if( ( i_bits >> i_count )&0x01 )
+ {
+ *s->p |= 1 << ( s->i_left - 1 );
+ }
+ else
+ {
+ *s->p &= ~( 1 << ( s->i_left - 1 ) );
+ }
+ s->i_left--;
+ if( s->i_left == 0 )
+ {
+ s->p++;
+ s->i_left = 8;
+ }
+ }
+}
+
+static inline void bs_write1( bs_t *s, uint32_t i_bits )
+{
+ if( s->p < s->p_end )
+ {
+ s->i_left--;
+
+ if( i_bits&0x01 )
+ {
+ *s->p |= 1 << s->i_left;
+ }
+ else
+ {
+ *s->p &= ~( 1 << s->i_left );
+ }
+ if( s->i_left == 0 )
+ {
+ s->p++;
+ s->i_left = 8;
+ }
+ }
+}
+
+static inline void bs_align( bs_t *s )
+{
+ if( s->i_left != 8 )
+ {
+ s->i_left = 8;
+ s->p++;
+ }
+}
+static inline void bs_align_0( bs_t *s )
+{
+ if( s->i_left != 8 )
+ {
+ bs_write( s, s->i_left, 0 );
+ }
+}
+static inline void bs_align_1( bs_t *s )
+{
+ if( s->i_left != 8 )
+ {
+ bs_write( s, s->i_left, 1 );
+ }
+}
+
+
+
+/* golomb functions */
+
+static inline void bs_write_ue( bs_t *s, unsigned int val )
+{
+ int i_size = 0;
+ static const int i_size0_255[256] =
+ {
+ 1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+ 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
+ };
+
+ if( val == 0 )
+ {
+ bs_write( s, 1, 1 );
+ }
+ else
+ {
+ unsigned int tmp = ++val;
+
+ if( tmp >= 0x00010000 )
+ {
+ i_size += 16;
+ tmp >>= 16;
+ }
+ if( tmp >= 0x100 )
+ {
+ i_size += 8;
+ tmp >>= 8;
+ }
+ i_size += i_size0_255[tmp];
+
+ bs_write( s, 2 * i_size - 1, val );
+ }
+}
+
+static inline void bs_write_se( bs_t *s, int val )
+{
+ bs_write_ue( s, val <= 0 ? -val * 2 : val * 2 - 1);
+}
+
+static inline void bs_write_te( bs_t *s, int x, int val )
+{
+ if( x == 1 )
+ {
+ bs_write( s, 1, ~val );
+ }
+ else if( x > 1 )
+ {
+ bs_write_ue( s, val );
+ }
+}
+
+static inline void bs_rbsp_trailing( bs_t *s )
+{
+ bs_write( s, 1, 1 );
+ if( s->i_left != 8 )
+ {
+ bs_write( s, s->i_left, 0x00 );
+ }
+}
+
+static inline int bs_size_ue( unsigned int val )
+{
+ static const int i_size0_254[255] =
+ {
+ 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
+ 11,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
+ 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
+ 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
+ 13,13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
+ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
+ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
+ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
+ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
+ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15
+ };
+
+ if( val < 255 )
+ {
+ return i_size0_254[val];
+ }
+ else
+ {
+ int i_size = 0;
+
+ val++;
+
+ if( val >= 0x10000 )
+ {
+ i_size += 32;
+ val = (val >> 16) - 1;
+ }
+ if( val >= 0x100 )
+ {
+ i_size += 16;
+ val = (val >> 8) - 1;
+ }
+ return i_size0_254[val] + i_size;
+ }
+}
+
+static inline int bs_size_se( int val )
+{
+ return bs_size_ue( val <= 0 ? -val * 2 : val * 2 - 1);
+}
+
+static inline int bs_size_te( int x, int val )
+{
+ if( x == 1 )
+ {
+ return 1;
+ }
+ else if( x > 1 )
+ {
+ return bs_size_ue( val );
+ }
+ return 0;
+}
+
+
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * cabac.c: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: cabac.c,v 1.1 2004/06/03 19:27:06 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 <string.h>
+#include <stdio.h>
+
+#include "common.h"
+
+//#define TRACE 1
+
+/* Debugging purpose ONLY !!!! */
+#ifdef TRACE
+static int binCount = 0;
+#endif
+
+
+static const int x264_cabac_context_init_I[399][2] =
+{
+ /* 0 - 10 */
+ { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
+ { 2, 54 }, { 3, 74 }, { -28,127 }, { -23, 104 },
+ { -6, 53 }, { -1, 54 }, { 7, 51 },
+
+ /* 11 - 23 unsused for I */
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 },
+
+ /* 24- 39 */
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+
+ /* 40 - 53 */
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 },
+
+ /* 54 - 59 */
+ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 },
+
+ /* 60 - 69 */
+ { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
+ { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
+ { 13, 41 }, { 3, 62 },
+
+ /* 70 -> 87 */
+ { 0, 11 }, { 1, 55 }, { 0, 69 }, { -17, 127 },
+ { -13, 102 },{ 0, 82 }, { -7, 74 }, { -21, 107 },
+ { -27, 127 },{ -31, 127 },{ -24, 127 }, { -18, 95 },
+ { -27, 127 },{ -21, 114 },{ -30, 127 }, { -17, 123 },
+ { -12, 115 },{ -16, 122 },
+
+ /* 88 -> 104 */
+ { -11, 115 },{ -12, 63 }, { -2, 68 }, { -15, 84 },
+ { -13, 104 },{ -3, 70 }, { -8, 93 }, { -10, 90 },
+ { -30, 127 },{ -1, 74 }, { -6, 97 }, { -7, 91 },
+ { -20, 127 },{ -4, 56 }, { -5, 82 }, { -7, 76 },
+ { -22, 125 },
+
+ /* 105 -> 135 */
+ { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 },
+ { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 },
+ { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 },
+ { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 },
+ { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 },
+ { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 },
+ { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 },
+ { 14, 62 }, { -13, 108 },{ -15, 100 },
+
+ /* 136 -> 165 */
+ { -13, 101 },{ -13, 91 }, { -12, 94 }, { -10, 88 },
+ { -16, 84 }, { -10, 86 }, { -7, 83 }, { -13, 87 },
+ { -19, 94 }, { 1, 70 }, { 0, 72 }, { -5, 74 },
+ { 18, 59 }, { -8, 102 }, { -15, 100 }, { 0, 95 },
+ { -4, 75 }, { 2, 72 }, { -11, 75 }, { -3, 71 },
+ { 15, 46 }, { -13, 69 }, { 0, 62 }, { 0, 65 },
+ { 21, 37 }, { -15, 72 }, { 9, 57 }, { 16, 54 },
+ { 0, 62 }, { 12, 72 },
+
+ /* 166 -> 196 */
+ { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 },
+ { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 },
+ { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 },
+ { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 },
+ { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 },
+ { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 },
+ { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 },
+ { 0, 89 }, { 26, -19 }, { 22, -17 },
+
+ /* 197 -> 226 */
+ { 26, -17 }, { 30, -25 }, { 28, -20 }, { 33, -23 },
+ { 37, -27 }, { 33, -23 }, { 40, -28 }, { 38, -17 },
+ { 33, -11 }, { 40, -15 }, { 41, -6 }, { 38, 1 },
+ { 41, 17 }, { 30, -6 }, { 27, 3 }, { 26, 22 },
+ { 37, -16 }, { 35, -4 }, { 38, -8 }, { 38, -3 },
+ { 37, 3 }, { 38, 5 }, { 42, 0 }, { 35, 16 },
+ { 39, 22 }, { 14, 48 }, { 27, 37 }, { 21, 60 },
+ { 12, 68 }, { 2, 97 },
+
+ /* 227 -> 251 */
+ { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 },
+ { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 },
+ { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 },
+ { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 },
+ { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 },
+ { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 },
+ { -4, 65 },
+
+ /* 252 -> 275 */
+ { -12, 73 }, { -8, 76 }, { -7, 80 }, { -9, 88 },
+ { -17, 110 },{ -11, 97 }, { -20, 84 }, { -11, 79 },
+ { -6, 73 }, { -4, 74 }, { -13, 86 }, { -13, 96 },
+ { -11, 97 }, { -19, 117 },{ -8, 78 }, { -5, 33 },
+ { -4, 48 }, { -2, 53 }, { -3, 62 }, { -13, 71 },
+ { -10, 79 }, { -12, 86 }, { -13, 90 }, { -14, 97 },
+
+ /* 276 a bit special (not used, x264_cabac_encode_bypass is used instead) */
+ { 0, 0 },
+
+ /* 277 -> 307 */
+ { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 },
+ { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 },
+ { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 },
+ { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 },
+ { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 },
+ { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 },
+ { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 },
+ { 9, 64 }, { -12, 104 },{ -11, 97 },
+
+ /* 308 -> 337 */
+ { -16, 96 }, { -7, 88 }, { -8, 85 }, { -7, 85 },
+ { -9, 85 }, { -13, 88 }, { 4, 66 }, { -3, 77 },
+ { -3, 76 }, { -6, 76 }, { 10, 58 }, { -1, 76 },
+ { -1, 83 }, { -7, 99 }, { -14, 95 }, { 2, 95 },
+ { 0, 76 }, { -5, 74 }, { 0, 70 }, { -11, 75 },
+ { 1, 68 }, { 0, 65 }, { -14, 73 }, { 3, 62 },
+ { 4, 62 }, { -1, 68 }, { -13, 75 }, { 11, 55 },
+ { 5, 64 }, { 12, 70 },
+
+ /* 338 -> 368 */
+ { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 },
+ { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 },
+ { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 },
+ { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 },
+ { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 },
+ { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 },
+ { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 },
+ { -12, 109 },{ 36, -35 }, { 36, -34 },
+
+ /* 369 -> 398 */
+ { 32, -26 }, { 37, -30 }, { 44, -32 }, { 34, -18 },
+ { 34, -15 }, { 40, -15 }, { 33, -7 }, { 35, -5 },
+ { 33, 0 }, { 38, 2 }, { 33, 13 }, { 23, 35 },
+ { 13, 58 }, { 29, -3 }, { 26, 0 }, { 22, 30 },
+ { 31, -7 }, { 35, -15 }, { 34, -3 }, { 34, 3 },
+ { 36, -1 }, { 34, 5 }, { 32, 11 }, { 35, 5 },
+ { 34, 12 }, { 39, 11 }, { 30, 29 }, { 34, 26 },
+ { 29, 39 }, { 19, 66 }
+};
+
+static const int x264_cabac_context_init_PB[3][399][2] =
+{
+ /* i_cabac_init_idc == 0 */
+ {
+ /* 0 - 10 */
+ { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
+ { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
+ { -6, 53 }, { -1, 54 }, { 7, 51 },
+
+ /* 11 - 23 */
+ { 23, 33 }, { 23, 2 }, { 21, 0 }, { 1, 9 },
+ { 0, 49 }, { -37, 118 }, { 5, 57 }, { -13, 78 },
+ { -11, 65 }, { 1, 62 }, { 12, 49 }, { -4, 73 },
+ { 17, 50 },
+
+ /* 24 - 39 */
+ { 18, 64 }, { 9, 43 }, { 29, 0 }, { 26, 67 },
+ { 16, 90 }, { 9, 104 }, { -46, 127 }, { -20, 104 },
+ { 1, 67 }, { -13, 78 }, { -11, 65 }, { 1, 62 },
+ { -6, 86 }, { -17, 95 }, { -6, 61 }, { 9, 45 },
+
+ /* 40 - 53 */
+ { -3, 69 }, { -6, 81 }, { -11, 96 }, { 6, 55 },
+ { 7, 67 }, { -5, 86 }, { 2, 88 }, { 0, 58 },
+ { -3, 76 }, { -10, 94 }, { 5, 54 }, { 4, 69 },
+ { -3, 81 }, { 0, 88 },
+
+ /* 54 - 59 */
+ { -7, 67 }, { -5, 74 }, { -4, 74 }, { -5, 80 },
+ { -7, 72 }, { 1, 58 },
+
+ /* 60 - 69 */
+ { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
+ { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
+ { 13, 41 }, { 3, 62 },
+
+ /* 70 - 87 */
+ { 0, 45 }, { -4, 78 }, { -3, 96 }, { -27, 126 },
+ { -28, 98 }, { -25, 101 }, { -23, 67 }, { -28, 82 },
+ { -20, 94 }, { -16, 83 }, { -22, 110 }, { -21, 91 },
+ { -18, 102 }, { -13, 93 }, { -29, 127 }, { -7, 92 },
+ { -5, 89 }, { -7, 96 }, { -13, 108 }, { -3, 46 },
+ { -1, 65 }, { -1, 57 }, { -9, 93 }, { -3, 74 },
+ { -9, 92 }, { -8, 87 }, { -23, 126 }, { 5, 54 },
+ { 6, 60 }, { 6, 59 }, { 6, 69 }, { -1, 48 },
+ { 0, 68 }, { -4, 69 }, { -8, 88 },
+
+ /* 105 -> 165 */
+ { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 },
+ { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 },
+ { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 },
+ { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 },
+ { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 },
+ { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 },
+ { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 },
+ { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 },
+ { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 },
+ { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 },
+ { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 },
+ { 3, 64 }, { 1, 61 }, { 9, 63 }, { 7, 50 },
+ { 16, 39 }, { 5, 44 }, { 4, 52 }, { 11, 48 },
+ { -5, 60 }, { -1, 59 }, { 0, 59 }, { 22, 33 },
+ { 5, 44 }, { 14, 43 }, { -1, 78 }, { 0, 60 },
+ { 9, 69 },
+
+ /* 166 - 226 */
+ { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 },
+ { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 },
+ { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 },
+ { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 },
+ { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 },
+ { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 },
+ { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 },
+ { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 },
+ { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 },
+ { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 },
+ { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 },
+ { 1, 67 }, { 5, 59 }, { 9, 67 }, { 16, 30 },
+ { 18, 32 }, { 18, 35 }, { 22, 29 }, { 24, 31 },
+ { 23, 38 }, { 18, 43 }, { 20, 41 }, { 11, 63 },
+ { 9, 59 }, { 9, 64 }, { -1, 94 }, { -2, 89 },
+ { -9, 108 },
+
+ /* 227 - 275 */
+ { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 },
+ { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 },
+ { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 },
+ { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 },
+ { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 },
+ { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 },
+ { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 },
+ { -3, 74 }, { -10, 90 }, { 0, 70 }, { -4, 29 },
+ { 5, 31 }, { 7, 42 }, { 1, 59 }, { -2, 58 },
+ { -3, 72 }, { -3, 81 }, { -11, 97 }, { 0, 58 },
+ { 8, 5 }, { 10, 14 }, { 14, 18 }, { 13, 27 },
+ { 2, 40 }, { 0, 58 }, { -3, 70 }, { -6, 79 },
+ { -8, 85 },
+
+ /* 276 a bit special (not used, x264_cabac_encode_bypass is used instead) */
+ { 0, 0 },
+
+ /* 277 - 337 */
+ { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 },
+ { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 },
+ { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
+ { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 },
+ { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 },
+ { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 },
+ { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 },
+ { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 },
+ { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 },
+ { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 },
+ { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 },
+ { -2, 69 }, { -2, 59 }, { 6, 70 }, { 10, 44 },
+ { 9, 31 }, { 12, 43 }, { 3, 53 }, { 14, 34 },
+ { 10, 38 }, { -3, 52 }, { 13, 40 }, { 17, 32 },
+ { 7, 44 }, { 7, 38 }, { 13, 50 }, { 10, 57 },
+ { 26, 43 },
+
+ /* 338 - 398 */
+ { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 },
+ { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 },
+ { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 },
+ { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 },
+ { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 },
+ { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 },
+ { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 },
+ { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 },
+ { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 },
+ { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 },
+ { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 },
+ { 8, 60 }, { 6, 63 }, { 17, 65 }, { 21, 24 },
+ { 23, 20 }, { 26, 23 }, { 27, 32 }, { 28, 23 },
+ { 28, 24 }, { 23, 40 }, { 24, 32 }, { 28, 29 },
+ { 23, 42 }, { 19, 57 }, { 22, 53 }, { 22, 61 },
+ { 11, 86 },
+
+
+ },
+
+ /* i_cabac_init_idc == 1 */
+ {
+ /* 0 - 10 */
+ { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
+ { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
+ { -6, 53 }, { -1, 54 }, { 7, 51 },
+
+ /* 11 - 23 */
+ { 22, 25 }, { 34, 0 }, { 16, 0 }, { -2, 9 },
+ { 4, 41 }, { -29, 118 }, { 2, 65 }, { -6, 71 },
+ { -13, 79 }, { 5, 52 }, { 9, 50 }, { -3, 70 },
+ { 10, 54 },
+
+ /* 24 - 39 */
+ { 26, 34 }, { 19, 22 }, { 40, 0 }, { 57, 2 },
+ { 41, 36 }, { 26, 69 }, { -45, 127 }, { -15, 101 },
+ { -4, 76 }, { -6, 71 }, { -13, 79 }, { 5, 52 },
+ { 6, 69 }, { -13, 90 }, { 0, 52 }, { 8, 43 },
+
+ /* 40 - 53 */
+ { -2, 69 },{ -5, 82 },{ -10, 96 },{ 2, 59 },
+ { 2, 75 },{ -3, 87 },{ -3, 100 },{ 1, 56 },
+ { -3, 74 },{ -6, 85 },{ 0, 59 },{ -3, 81 },
+ { -7, 86 },{ -5, 95 },
+
+ /* 54 - 59 */
+ { -1, 66 },{ -1, 77 },{ 1, 70 },{ -2, 86 },
+ { -5, 72 },{ 0, 61 },
+
+ /* 60 - 69 */
+ { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
+ { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
+ { 13, 41 }, { 3, 62 },
+
+ /* 70 - 104 */
+ { 13, 15 }, { 7, 51 }, { 2, 80 }, { -39, 127 },
+ { -18, 91 }, { -17, 96 }, { -26, 81 }, { -35, 98 },
+ { -24, 102 }, { -23, 97 }, { -27, 119 }, { -24, 99 },
+ { -21, 110 }, { -18, 102 }, { -36, 127 }, { 0, 80 },
+ { -5, 89 }, { -7, 94 }, { -4, 92 }, { 0, 39 },
+ { 0, 65 }, { -15, 84 }, { -35, 127 }, { -2, 73 },
+ { -12, 104 }, { -9, 91 }, { -31, 127 }, { 3, 55 },
+ { 7, 56 }, { 7, 55 }, { 8, 61 }, { -3, 53 },
+ { 0, 68 }, { -7, 74 }, { -9, 88 },
+
+ /* 105 -> 165 */
+ { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 },
+ { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 },
+ { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 },
+ { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 },
+ { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 },
+ { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 },
+ { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 },
+ { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 },
+ { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 },
+ { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 },
+ { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 },
+ { -4, 71 }, { 0, 58 }, { 7, 61 }, { 9, 41 },
+ { 18, 25 }, { 9, 32 }, { 5, 43 }, { 9, 47 },
+ { 0, 44 }, { 0, 51 }, { 2, 46 }, { 19, 38 },
+ { -4, 66 }, { 15, 38 }, { 12, 42 }, { 9, 34 },
+ { 0, 89 },
+
+ /* 166 - 226 */
+ { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 },
+ { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 },
+ { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 },
+ { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 },
+ { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 },
+ { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 },
+ { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 },
+ { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 },
+ { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 },
+ { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 },
+ { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 },
+ { 0, 75 }, { 2, 72 }, { 8, 77 }, { 14, 35 },
+ { 18, 31 }, { 17, 35 }, { 21, 30 }, { 17, 45 },
+ { 20, 42 }, { 18, 45 }, { 27, 26 }, { 16, 54 },
+ { 7, 66 }, { 16, 56 }, { 11, 73 }, { 10, 67 },
+ { -10, 116 },
+
+ /* 227 - 275 */
+ { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 },
+ { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 },
+ { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 },
+ { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 },
+ { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 },
+ { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 },
+ { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 },
+ { -5, 74 }, { -9, 86 }, { 2, 66 }, { -9, 34 },
+ { 1, 32 }, { 11, 31 }, { 5, 52 }, { -2, 55 },
+ { -2, 67 }, { 0, 73 }, { -8, 89 }, { 3, 52 },
+ { 7, 4 }, { 10, 8 }, { 17, 8 }, { 16, 19 },
+ { 3, 37 }, { -1, 61 }, { -5, 73 }, { -1, 70 },
+ { -4, 78 },
+
+ /* 276 a bit special (not used, x264_cabac_encode_bypass is used instead) */
+ { 0, 0 },
+
+ /* 277 - 337 */
+ { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
+ { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
+ { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
+ { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 },
+ { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 },
+ { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 },
+ { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 },
+ { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 },
+ { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 },
+ { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 },
+ { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 },
+ { -1, 70 }, { -9, 72 }, { 14, 60 }, { 16, 37 },
+ { 0, 47 }, { 18, 35 }, { 11, 37 }, { 12, 41 },
+ { 10, 41 }, { 2, 48 }, { 12, 41 }, { 13, 41 },
+ { 0, 59 }, { 3, 50 }, { 19, 40 }, { 3, 66 },
+ { 18, 50 },
+
+ /* 338 - 398 */
+ { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 },
+ { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 },
+ { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 },
+ { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 },
+ { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 },
+ { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 },
+ { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 },
+ { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 },
+ { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 },
+ { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 },
+ { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 },
+ { 12, 48 }, { 11, 49 }, { 26, 45 }, { 22, 22 },
+ { 23, 22 }, { 27, 21 }, { 33, 20 }, { 26, 28 },
+ { 30, 24 }, { 27, 34 }, { 18, 42 }, { 25, 39 },
+ { 18, 50 }, { 12, 70 }, { 21, 54 }, { 14, 71 },
+ { 11, 83 },
+
+ },
+
+ /* i_cabac_init_idc == 2 */
+ {
+ /* 0 - 10 */
+ { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
+ { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
+ { -6, 53 }, { -1, 54 }, { 7, 51 },
+
+ /* 11 - 23 */
+ { 29, 16 }, { 25, 0 }, { 14, 0 }, { -10, 51 },
+ { -3, 62 }, { -27, 99 }, { 26, 16 }, { -4, 85 },
+ { -24, 102 }, { 5, 57 }, { 6, 57 }, { -17, 73 },
+ { 14, 57 },
+
+ /* 24 - 39 */
+ { 20, 40 }, { 20, 10 }, { 29, 0 }, { 54, 0 },
+ { 37, 42 }, { 12, 97 }, { -32, 127 }, { -22, 117 },
+ { -2, 74 }, { -4, 85 }, { -24, 102 }, { 5, 57 },
+ { -6, 93 }, { -14, 88 }, { -6, 44 }, { 4, 55 },
+
+ /* 40 - 53 */
+ { -11, 89 },{ -15, 103 },{ -21, 116 },{ 19, 57 },
+ { 20, 58 },{ 4, 84 },{ 6, 96 },{ 1, 63 },
+ { -5, 85 },{ -13, 106 },{ 5, 63 },{ 6, 75 },
+ { -3, 90 },{ -1, 101 },
+
+ /* 54 - 59 */
+ { 3, 55 },{ -4, 79 },{ -2, 75 },{ -12, 97 },
+ { -7, 50 },{ 1, 60 },
+
+ /* 60 - 69 */
+ { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
+ { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
+ { 13, 41 }, { 3, 62 },
+
+ /* 70 - 104 */
+ { 7, 34 }, { -9, 88 }, { -20, 127 }, { -36, 127 },
+ { -17, 91 }, { -14, 95 }, { -25, 84 }, { -25, 86 },
+ { -12, 89 }, { -17, 91 }, { -31, 127 }, { -14, 76 },
+ { -18, 103 }, { -13, 90 }, { -37, 127 }, { 11, 80 },
+ { 5, 76 }, { 2, 84 }, { 5, 78 }, { -6, 55 },
+ { 4, 61 }, { -14, 83 }, { -37, 127 }, { -5, 79 },
+ { -11, 104 }, { -11, 91 }, { -30, 127 }, { 0, 65 },
+ { -2, 79 }, { 0, 72 }, { -4, 92 }, { -6, 56 },
+ { 3, 68 }, { -8, 71 }, { -13, 98 },
+
+ /* 105 -> 165 */
+ { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 },
+ { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 },
+ { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 },
+ { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 },
+ { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 },
+ { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 },
+ { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 },
+ { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 },
+ { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 },
+ { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 },
+ { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 },
+ { 3, 65 }, { -7, 69 }, { 8, 77 }, { -10, 66 },
+ { 3, 62 }, { -3, 68 }, { -20, 81 }, { 0, 30 },
+ { 1, 7 }, { -3, 23 }, { -21, 74 }, { 16, 66 },
+ { -23, 124 }, { 17, 37 }, { 44, -18 }, { 50, -34 },
+ { -22, 127 },
+
+ /* 166 - 226 */
+ { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 },
+ { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 },
+ { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 },
+ { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 },
+ { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 },
+ { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 },
+ { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 },
+ { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 },
+ { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 },
+ { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 },
+ { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 },
+ { 20, 34 }, { 19, 31 }, { 27, 44 }, { 19, 16 },
+ { 15, 36 }, { 15, 36 }, { 21, 28 }, { 25, 21 },
+ { 30, 20 }, { 31, 12 }, { 27, 16 }, { 24, 42 },
+ { 0, 93 }, { 14, 56 }, { 15, 57 }, { 26, 38 },
+ { -24, 127 },
+
+ /* 227 - 275 */
+ { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 },
+ { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 },
+ { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 },
+ { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 },
+ { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 },
+ { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 },
+ { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 },
+ { -12, 92 }, { -18, 108 }, { -4, 79 }, { -22, 69 },
+ { -16, 75 }, { -2, 58 }, { 1, 58 }, { -13, 78 },
+ { -9, 83 }, { -4, 81 }, { -13, 99 }, { -13, 81 },
+ { -6, 38 }, { -13, 62 }, { -6, 58 }, { -2, 59 },
+ { -16, 73 }, { -10, 76 }, { -13, 86 }, { -9, 83 },
+ { -10, 87 },
+
+ /* 276 a bit special (not used, x264_cabac_encode_bypass is used instead) */
+ { 0, 0 },
+
+ /* 277 - 337 */
+ { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
+ { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
+ { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
+ { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 },
+ { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 },
+ { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 },
+ { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 },
+ { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 },
+ { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 },
+ { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 },
+ { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 },
+ { -2, 76 }, { -18, 86 }, { 12, 70 }, { 5, 64 },
+ { -12, 70 }, { 11, 55 }, { 5, 56 }, { 0, 69 },
+ { 2, 65 }, { -6, 74 }, { 5, 54 }, { 7, 54 },
+ { -6, 76 }, { -11, 82 }, { -2, 77 }, { -2, 77 },
+ { 25, 42 },
+
+ /* 338 - 398 */
+ { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 },
+ { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 },
+ { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 },
+ { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 },
+ { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 },
+ { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 },
+ { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 },
+ { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 },
+ { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 },
+ { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 },
+ { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 },
+ { 18, 31 }, { 19, 26 }, { 36, 24 }, { 24, 23 },
+ { 27, 16 }, { 24, 30 }, { 31, 29 }, { 22, 41 },
+ { 22, 42 }, { 16, 60 }, { 15, 52 }, { 14, 60 },
+ { 3, 78 }, { -16, 123 }, { 21, 53 }, { 22, 56 },
+ { 25, 61 },
+ }
+};
+
+static const int x264_cabac_range_lps[64][4] =
+{
+ { 128, 176, 208, 240 }, { 128, 167, 197, 227 }, { 128, 158, 187, 216 },
+ { 123, 150, 178, 205 }, { 116, 142, 169, 195 }, { 111, 135, 160, 185 },
+ { 105, 128, 152, 175 }, { 100, 122, 144, 166 }, { 95, 116, 137, 158 },
+ { 90, 110, 130, 150 }, { 85, 104, 123, 142 }, { 81, 99, 117, 135 },
+ { 77, 94, 111, 128 }, { 73, 89, 105, 122 }, { 69, 85, 100, 116 },
+ { 66, 80, 95, 110 }, { 62, 76, 90, 104 }, { 59, 72, 86, 99 },
+ { 56, 69, 81, 94 }, { 53, 65, 77, 89 }, { 51, 62, 73, 85 },
+ { 48, 59, 69, 80 }, { 46, 56, 66, 76 }, { 43, 53, 63, 72 },
+ { 41, 50, 59, 69 }, { 39, 48, 56, 65 }, { 37, 45, 54, 62 },
+ { 35, 43, 51, 59 }, { 33, 41, 48, 56 }, { 32, 39, 46, 53 },
+ { 30, 37, 43, 50 }, { 29, 35, 41, 48 }, { 27, 33, 39, 45 },
+ { 26, 31, 37, 43 }, { 24, 30, 35, 41 }, { 23, 28, 33, 39 },
+ { 22, 27, 32, 37 }, { 21, 26, 30, 35 }, { 20, 24, 29, 33 },
+ { 19, 23, 27, 31 }, { 18, 22, 26, 30 }, { 17, 21, 25, 28 },
+ { 16, 20, 23, 27 }, { 15, 19, 22, 25 }, { 14, 18, 21, 24 },
+ { 14, 17, 20, 23 }, { 13, 16, 19, 22 }, { 12, 15, 18, 21 },
+ { 12, 14, 17, 20 }, { 11, 14, 16, 19 }, { 11, 13, 15, 18 },
+ { 10, 12, 15, 17 }, { 10, 12, 14, 16 }, { 9, 11, 13, 15 },
+ { 9, 11, 12, 14 }, { 8, 10, 12, 14 }, { 8, 9, 11, 13 },
+ { 7, 9, 11, 12 }, { 7, 9, 10, 12 }, { 7, 8, 10, 11 },
+ { 6, 8, 9, 11 }, { 6, 7, 9, 10 }, { 6, 7, 8, 9 },
+ { 2, 2, 2, 2 },
+};
+
+static const int x264_transition_lps[64] =
+{
+ 0, 0, 1, 2, 2, 4, 4, 5, 6, 7, 8, 9, 9,11,11,12,
+ 13,13,15,15,16,16,18,18,19,19,21,21,22,22,23,24,
+ 24,25,26,26,27,27,28,29,29,30,30,30,31,32,32,33,
+ 33,33,34,34,35,35,35,36,36,36,37,37,37,38,38,63
+};
+static const int x264_transition_mps[64] =
+{
+ 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,
+ 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
+ 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
+ 49,50,51,52,53,54,55,56,57,58,59,60,61,62,62,63,
+};
+
+#define FIX8(f) ((int)(f*(1<<8)))
+static int x264_cabac_probability[128] =
+{
+ FIX8(0.9812), FIX8(0.9802), FIX8(0.9792), FIX8(0.9781),
+ FIX8(0.9769), FIX8(0.9757), FIX8(0.9744), FIX8(0.9730),
+ FIX8(0.9716), FIX8(0.9700), FIX8(0.9684), FIX8(0.9667),
+ FIX8(0.9650), FIX8(0.9631), FIX8(0.9611), FIX8(0.9590),
+ FIX8(0.9568), FIX8(0.9545), FIX8(0.9521), FIX8(0.9495),
+ FIX8(0.9468), FIX8(0.9440), FIX8(0.9410), FIX8(0.9378),
+ FIX8(0.9345), FIX8(0.9310), FIX8(0.9273), FIX8(0.9234),
+ FIX8(0.9193), FIX8(0.9150), FIX8(0.9105), FIX8(0.9057),
+ FIX8(0.9006), FIX8(0.8953), FIX8(0.8897), FIX8(0.8838),
+ FIX8(0.8776), FIX8(0.8710), FIX8(0.8641), FIX8(0.8569),
+ FIX8(0.8492), FIX8(0.8411), FIX8(0.8326), FIX8(0.8237),
+ FIX8(0.8143), FIX8(0.8043), FIX8(0.7938), FIX8(0.7828),
+ FIX8(0.7712), FIX8(0.7590), FIX8(0.7461), FIX8(0.7325),
+ FIX8(0.7182), FIX8(0.7031), FIX8(0.6872), FIX8(0.6705),
+ FIX8(0.6528), FIX8(0.6343), FIX8(0.6147), FIX8(0.5941),
+ FIX8(0.5724), FIX8(0.5495), FIX8(0.5254), FIX8(0.5000),
+ FIX8(0.5000), FIX8(0.4746), FIX8(0.4505), FIX8(0.4276),
+ FIX8(0.4059), FIX8(0.3853), FIX8(0.3657), FIX8(0.3472),
+ FIX8(0.3295), FIX8(0.3128), FIX8(0.2969), FIX8(0.2818),
+ FIX8(0.2675), FIX8(0.2539), FIX8(0.2410), FIX8(0.2288),
+ FIX8(0.2172), FIX8(0.2062), FIX8(0.1957), FIX8(0.1857),
+ FIX8(0.1763), FIX8(0.1674), FIX8(0.1589), FIX8(0.1508),
+ FIX8(0.1431), FIX8(0.1359), FIX8(0.1290), FIX8(0.1224),
+ FIX8(0.1162), FIX8(0.1103), FIX8(0.1047), FIX8(0.0994),
+ FIX8(0.0943), FIX8(0.0895), FIX8(0.0850), FIX8(0.0807),
+ FIX8(0.0766), FIX8(0.0727), FIX8(0.0690), FIX8(0.0655),
+ FIX8(0.0622), FIX8(0.0590), FIX8(0.0560), FIX8(0.0532),
+ FIX8(0.0505), FIX8(0.0479), FIX8(0.0455), FIX8(0.0432),
+ FIX8(0.0410), FIX8(0.0389), FIX8(0.0369), FIX8(0.0350),
+ FIX8(0.0333), FIX8(0.0316), FIX8(0.0300), FIX8(0.0284),
+ FIX8(0.0270), FIX8(0.0256), FIX8(0.0243), FIX8(0.0231),
+ FIX8(0.0219), FIX8(0.0208), FIX8(0.0198), FIX8(0.0187)
+};
+/* -ln2(probability) */
+static int x264_cabac_entropy[128] =
+{
+ FIX8(0.0273), FIX8(0.0288), FIX8(0.0303), FIX8(0.0320),
+ FIX8(0.0337), FIX8(0.0355), FIX8(0.0375), FIX8(0.0395),
+ FIX8(0.0416), FIX8(0.0439), FIX8(0.0463), FIX8(0.0488),
+ FIX8(0.0515), FIX8(0.0543), FIX8(0.0572), FIX8(0.0604),
+ FIX8(0.0637), FIX8(0.0671), FIX8(0.0708), FIX8(0.0747),
+ FIX8(0.0788), FIX8(0.0832), FIX8(0.0878), FIX8(0.0926),
+ FIX8(0.0977), FIX8(0.1032), FIX8(0.1089), FIX8(0.1149),
+ FIX8(0.1214), FIX8(0.1282), FIX8(0.1353), FIX8(0.1429),
+ FIX8(0.1510), FIX8(0.1596), FIX8(0.1686), FIX8(0.1782),
+ FIX8(0.1884), FIX8(0.1992), FIX8(0.2107), FIX8(0.2229),
+ FIX8(0.2358), FIX8(0.2496), FIX8(0.2642), FIX8(0.2798),
+ FIX8(0.2964), FIX8(0.3142), FIX8(0.3331), FIX8(0.3532),
+ FIX8(0.3748), FIX8(0.3979), FIX8(0.4226), FIX8(0.4491),
+ FIX8(0.4776), FIX8(0.5082), FIX8(0.5412), FIX8(0.5768),
+ FIX8(0.6152), FIX8(0.6568), FIX8(0.7020), FIX8(0.7513),
+ FIX8(0.8050), FIX8(0.8638), FIX8(0.9285), FIX8(1.0000),
+ FIX8(1.0000), FIX8(1.0752), FIX8(1.1504), FIX8(1.2256),
+ FIX8(1.3008), FIX8(1.3759), FIX8(1.4511), FIX8(1.5263),
+ FIX8(1.6015), FIX8(1.6767), FIX8(1.7519), FIX8(1.8271),
+ FIX8(1.9023), FIX8(1.9775), FIX8(2.0527), FIX8(2.1278),
+ FIX8(2.2030), FIX8(2.2782), FIX8(2.3534), FIX8(2.4286),
+ FIX8(2.5038), FIX8(2.5790), FIX8(2.6542), FIX8(2.7294),
+ FIX8(2.8046), FIX8(2.8797), FIX8(2.9549), FIX8(3.0301),
+ FIX8(3.1053), FIX8(3.1805), FIX8(3.2557), FIX8(3.3309),
+ FIX8(3.4061), FIX8(3.4813), FIX8(3.5565), FIX8(3.6316),
+ FIX8(3.7068), FIX8(3.7820), FIX8(3.8572), FIX8(3.9324),
+ FIX8(4.0076), FIX8(4.0828), FIX8(4.1580), FIX8(4.2332),
+ FIX8(4.3083), FIX8(4.3836), FIX8(4.4588), FIX8(4.5339),
+ FIX8(4.6091), FIX8(4.6843), FIX8(4.7595), FIX8(4.8347),
+ FIX8(4.9099), FIX8(4.9851), FIX8(5.0602), FIX8(5.1354),
+ FIX8(5.2106), FIX8(5.2859), FIX8(5.3610), FIX8(5.4362),
+ FIX8(5.5114), FIX8(5.5866), FIX8(5.6618), FIX8(5.7370)
+};
+
+#undef FIX8
+
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model )
+{
+ const int (*cabac_context_init)[399][2];
+ int i;
+
+ if( i_slice_type == SLICE_TYPE_I )
+ {
+ cabac_context_init = &x264_cabac_context_init_I;
+ }
+ else
+ {
+ cabac_context_init = &x264_cabac_context_init_PB[i_model];
+ }
+
+ for( i = 0; i < 399; i++ )
+ {
+ int i_pre_state;
+
+ i_pre_state = x264_clip3( (((*cabac_context_init)[i][0] * i_qp) >> 4) + (*cabac_context_init)[i][1], 1, 126 );
+ if( i_pre_state <= 63 )
+ {
+ cb->ctxstate[i].i_state = 63 - i_pre_state;
+ cb->ctxstate[i].i_mps = 0;
+ }
+ else
+ {
+ cb->ctxstate[i].i_state = i_pre_state - 64;
+ cb->ctxstate[i].i_mps = 1;
+ }
+ cb->ctxstate[i].i_count = 0;
+ }
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+void x264_cabac_decode_init( x264_cabac_t *cb, bs_t *s )
+{
+ cb->i_range = 0x01fe;
+ cb->i_low = bs_read( s, 9 );
+ cb->s = s;
+}
+
+static inline void x264_cabac_decode_renorm( x264_cabac_t *cb )
+{
+ while( cb->i_range < 0x0100 )
+ {
+ cb->i_range <<= 1;
+ cb->i_low = ( cb->i_low << 1 )|bs_read( cb->s, 1 );
+ }
+}
+
+int x264_cabac_decode_decision( x264_cabac_t *cb, int i_ctx )
+{
+ int i_state = cb->ctxstate[i_ctx].i_state;
+ int i_mps = cb->ctxstate[i_ctx].i_mps;
+
+ int i_range_lps = x264_cabac_range_lps[i_state][(cb->i_range>>6)&0x03];
+
+ int val;
+
+ cb->i_range -= i_range_lps;
+
+ if( cb->i_low >= cb->i_range )
+ {
+ val = 1 - i_mps;
+
+ cb->i_low -= cb->i_range;
+ cb->i_range= i_range_lps;
+
+ if( i_state == 0 )
+ {
+ cb->ctxstate[i_ctx].i_mps = 1 - i_mps;
+ }
+ cb->ctxstate[i_ctx].i_state = x264_transition_lps[i_state];
+ }
+ else
+ {
+ val = i_mps;
+
+ cb->ctxstate[i_ctx].i_state = x264_transition_mps[i_state];
+ }
+
+ x264_cabac_decode_renorm( cb );
+
+ return val;
+}
+int x264_cabac_decode_bypass( x264_cabac_t *cb )
+{
+ cb->i_low = (cb->i_low << 1)|bs_read( cb->s, 1 );
+
+ if( cb->i_low >= cb->i_range )
+ {
+ cb->i_low -= cb->i_range;
+ return 1;
+ }
+ return 0;
+}
+int x264_cabac_decode_terminal( x264_cabac_t *cb )
+{
+ if( cb->i_low >= cb->i_range - 2 )
+ {
+ return 1;
+ }
+
+ cb->i_range -= 2;
+ x264_cabac_decode_renorm( cb );
+ return 0;
+}
+
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+void x264_cabac_model_init( x264_cabac_t *cb )
+{
+ int i;
+
+ for( i = 0; i < 3; i++ )
+ {
+ cb->slice[i].i_model = 0;
+ cb->slice[i].i_cost = -1;
+ }
+}
+
+int x264_cabac_model_get ( x264_cabac_t *cb, int i_slice_type )
+{
+ return cb->slice[i_slice_type].i_model;
+}
+
+void x264_cabac_model_update( x264_cabac_t *cb, int i_slice_type, int i_qp )
+{
+ int i;
+
+ if( i_slice_type == SLICE_TYPE_I )
+ {
+ return;
+ }
+ cb->slice[i_slice_type].i_cost = -1;
+
+ for( i = 0; i < 3; i++ )
+ {
+ int i_ctx;
+ int i_cost;
+
+ i_cost = 0; /* fix8 */
+
+ for( i_ctx = 0; i_ctx < 399; i_ctx++ )
+ {
+ int i_weight;
+ int i_model_state;
+ int i_ctx_state;
+
+ i_weight = X264_MIN( (1<<8), (cb->ctxstate[i_ctx].i_count<<8) / 32 );
+ i_model_state = x264_clip3( ((x264_cabac_context_init_PB[i][i_ctx][0] * i_qp)>>4) +
+ x264_cabac_context_init_PB[i][i_ctx][1], 0, 127 );
+ i_ctx_state = cb->ctxstate[i_ctx].i_mps ? 64 + cb->ctxstate[i_ctx].i_state : 63 - cb->ctxstate[i_ctx].i_state;
+
+ i_cost += (i_weight * (( x264_cabac_probability[ i_ctx_state] * x264_cabac_entropy[ i_model_state] +
+ x264_cabac_probability[127 - i_ctx_state] * x264_cabac_entropy[127 - i_model_state] ) >> 8))>>8;
+ }
+
+ if( cb->slice[i_slice_type].i_cost == -1 || cb->slice[i_slice_type].i_cost > i_cost )
+ {
+ cb->slice[i_slice_type].i_model= i;
+ cb->slice[i_slice_type].i_cost = i_cost;
+ }
+ }
+}
+
+void x264_cabac_encode_init( x264_cabac_t *cb, bs_t *s )
+{
+ cb->i_low = 0;
+ cb->i_range = 0x01FE;
+ cb->b_first_bit= 1;
+ cb->i_bits_outstanding = 0;
+ cb->i_sym_cnt = 0;
+ cb->s = s;
+}
+
+static inline void x264_cabac_putbit( x264_cabac_t *cb, int b )
+{
+ if( cb->b_first_bit )
+ {
+ cb->b_first_bit = 0;
+ }
+ else
+ {
+ bs_write1( cb->s, b );
+ }
+
+ while( cb->i_bits_outstanding > 0 )
+ {
+ bs_write1( cb->s, 1 - b );
+ cb->i_bits_outstanding--;
+ }
+}
+
+static inline void x264_cabac_encode_renorm( x264_cabac_t *cb )
+{
+ /* RenormE */
+ while( cb->i_range < 0x0100 )
+ {
+ if( cb->i_low < 0x100 )
+ {
+ x264_cabac_putbit( cb, 0 );
+ }
+ else
+ {
+ if( cb->i_low >= 0x200 )
+ {
+ cb->i_low -= 0x200;
+ x264_cabac_putbit( cb, 1 );
+ }
+ else
+ {
+ cb->i_low -= 0x100;
+ cb->i_bits_outstanding++;
+ }
+ }
+
+ cb->i_range <<= 1;
+ cb->i_low <<= 1;
+ }
+}
+
+void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx, int b )
+{
+ int i_state = cb->ctxstate[i_ctx].i_state;
+ int i_mps = cb->ctxstate[i_ctx].i_mps;
+
+ int i_range_lps = x264_cabac_range_lps[i_state][(cb->i_range>>6)&0x03];
+
+#ifdef TRACE
+ if( binCount >= 0 )
+ {
+ fprintf( stderr, "%d ctx=%d b=%d\n", binCount, i_ctx, b );
+ }
+ fprintf( stderr, "%d 0x%04x %d %d\n", binCount++, cb->i_range, i_state, i_mps );
+#endif
+
+ cb->i_range -= i_range_lps;
+
+ if( b != i_mps )
+ {
+ cb->i_low += cb->i_range;
+ cb->i_range = i_range_lps;
+
+ if( i_state == 0 )
+ {
+ cb->ctxstate[i_ctx].i_mps = 1 - i_mps;
+ }
+ cb->ctxstate[i_ctx].i_state = x264_transition_lps[i_state];
+ }
+ else
+ {
+ cb->ctxstate[i_ctx].i_state = x264_transition_mps[i_state];
+ }
+ cb->ctxstate[i_ctx].i_count++;
+
+ x264_cabac_encode_renorm( cb );
+
+ cb->i_sym_cnt++;
+}
+
+void x264_cabac_encode_bypass( x264_cabac_t *cb, int b )
+{
+#ifdef TRACE
+ fprintf( stderr, "%d 0x%04x\n", binCount++, cb->i_range );
+#endif
+
+ cb->i_low <<= 1;
+ if( b )
+ {
+ cb->i_low += cb->i_range;
+ }
+
+ if( cb->i_low >= 0x400 )
+ {
+ x264_cabac_putbit( cb, 1 );
+ cb->i_low -= 0x400;
+ }
+ else
+ {
+ if( cb->i_low < 0x200 )
+ {
+ x264_cabac_putbit( cb, 0 );
+ }
+ else
+ {
+ cb->i_low -= 0x200;
+ cb->i_bits_outstanding++;
+ }
+ }
+ cb->i_sym_cnt++;
+}
+
+void x264_cabac_encode_terminal( x264_cabac_t *cb, int b )
+{
+#ifdef TRACE
+ fprintf( stderr, "%d 0x%04x\n", binCount++, cb->i_range );
+#endif
+
+ cb->i_range -= 2;
+ if( b )
+ {
+ cb->i_low += cb->i_range;
+ cb->i_range = 2;
+ }
+ x264_cabac_encode_renorm( cb );
+
+ cb->i_sym_cnt++;
+}
+
+void x264_cabac_encode_flush( x264_cabac_t *cb )
+{
+ x264_cabac_putbit( cb, (cb->i_low >> 9)&0x01 );
+ bs_write1( cb->s, (cb->i_low >> 8)&0x01 );
+
+ /* check that */
+ bs_write1( cb->s, 0x01 );
+ bs_align_0( cb->s );
+}
+
--- /dev/null
+/*****************************************************************************
+ * cabac.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: cabac.h,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifndef _CABAC_H
+#define _CABAC_H 1
+
+typedef struct
+{
+ /* model */
+ struct
+ {
+ int i_model;
+ int i_cost;
+ } slice[3];
+
+ /* context */
+ struct
+ {
+ int i_state;
+ int i_mps;
+ int i_count;
+ } ctxstate[399];
+
+ /* state */
+ int i_low;
+ int i_range;
+
+ int i_sym_cnt;
+
+ /* bit stream */
+ int b_first_bit;
+ int i_bits_outstanding;
+ bs_t *s;
+
+} x264_cabac_t;
+
+/* encoder/decoder: init the contexts given i_slice_type, the quantif and the model */
+void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model );
+
+/* decoder only: */
+void x264_cabac_decode_init ( x264_cabac_t *cb, bs_t *s );
+int x264_cabac_decode_decision( x264_cabac_t *cb, int i_ctx_idx );
+int x264_cabac_decode_bypass ( x264_cabac_t *cb );
+int x264_cabac_decode_terminal( x264_cabac_t *cb );
+
+/* encoder only: adaptive model init */
+void x264_cabac_model_init( x264_cabac_t *cb );
+int x264_cabac_model_get ( x264_cabac_t *cb, int i_slice_type );
+void x264_cabac_model_update( x264_cabac_t *cb, int i_slice_type, int i_qp );
+/* encoder only: */
+void x264_cabac_encode_init ( x264_cabac_t *cb, bs_t *s );
+void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx_idx, int b );
+void x264_cabac_encode_bypass( x264_cabac_t *cb, int b );
+void x264_cabac_encode_terminal( x264_cabac_t *cb, int b );
+void x264_cabac_encode_flush( x264_cabac_t *cb );
+
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * clip1.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: clip1.h,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifndef _CLIP1_H
+#define _CLIP1_H 1
+
+/* Clip1 table
+ * XXX : only for tap filter.
+ *
+ * With tap filter (( 1, -5, 20, 20, -5, 1 ) + 16 )/ 32
+ * -> (-2*5 * 255+16)/32 <= out <= (2*1*255 + 2*20*255+16)/32
+ * -> -80 <= out <= 335
+ * So we need a table of 80+335+1 = 416 entries
+ */
+
+static const uint8_t x264_mc_clip1_table[80+1+335] =
+{
+ /* -80 -> -1 */
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,
+ /* 0 -> 255 */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+ 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
+ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,101,102,103,104,105,106,107,
+ 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
+ 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
+ 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,
+ 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
+ 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
+ 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
+ 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
+ 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
+ 252,253,254,255,
+ /* 256 -> 340 */
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,
+};
+
+static inline uint8_t x264_mc_clip1( int x )
+{
+ return x264_mc_clip1_table[x+80];
+}
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * common.c: h264 library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: common.c,v 1.1 2004/06/03 19:27:06 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 <stdarg.h>
+
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include "common.h"
+#include "cpu.h"
+
+static void x264_log_default( void *, int, const char *, va_list );
+
+/****************************************************************************
+ * x264_param_default:
+ ****************************************************************************/
+void x264_param_default( x264_param_t *param )
+{
+ /* */
+ memset( param, 0, sizeof( x264_param_t ) );
+
+ /* CPU autodetect */
+ param->cpu = x264_cpu_detect();
+
+ /* Video properties */
+ param->i_csp = X264_CSP_I420;
+ param->i_width = 0;
+ param->i_height = 0;
+ param->vui.i_sar_width = 0;
+ param->vui.i_sar_height= 0;
+ param->i_fps_num = 25;
+ param->i_fps_den = 1;
+
+ /* Encoder parameters */
+ param->i_frame_reference = 1;
+ param->i_idrframe = 2;
+ param->i_iframe = 60;
+ param->i_bframe = 0;
+ param->i_scenecut_threshold = 40;
+
+ param->b_deblocking_filter = 1;
+ param->i_deblocking_filter_alphac0 = 0;
+ param->i_deblocking_filter_beta = 0;
+
+ param->b_cabac = 0;
+ param->i_cabac_init_idc = -1;
+
+ param->rc.b_cbr = 0;
+ param->rc.i_bitrate = 3000;
+ param->rc.i_rc_buffer_size = 0;
+ param->rc.i_rc_init_buffer = 0;
+ param->rc.i_rc_sens = 100;
+ param->rc.i_qp_constant = 26;
+ param->rc.i_qp_min = 0;
+ param->rc.i_qp_max = 51;
+ param->rc.i_qp_step = 4;
+ param->rc.f_ip_factor = 1.4;
+ param->rc.f_pb_factor = 1.4;
+
+ param->rc.b_stat_write = 0;
+ param->rc.psz_stat_out = "x264_2pass.log";
+ param->rc.b_stat_read = 0;
+ param->rc.psz_stat_in = "x264_2pass.log";
+ param->rc.psz_rc_eq = "tex*blurTex^(qComp-1)";
+ param->rc.f_qcompress = 0.6;
+ param->rc.f_qblur = 0.5;
+ param->rc.f_complexity_blur = 20;
+
+ /* Log */
+ param->pf_log = x264_log_default;
+ param->p_log_private = NULL;
+ param->i_log_level = X264_LOG_DEBUG;
+
+ /* */
+ param->analyse.intra = X264_ANALYSE_I4x4;
+ param->analyse.inter = X264_ANALYSE_I4x4 | X264_ANALYSE_PSUB16x16;
+ param->analyse.i_subpel_refine = 1;
+ param->analyse.b_psnr = 1;
+}
+
+/****************************************************************************
+ * x264_log:
+ ****************************************************************************/
+void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... )
+{
+ if( i_level <= h->param.i_log_level )
+ {
+ va_list arg;
+ va_start( arg, psz_fmt );
+ h->param.pf_log( h->param.p_log_private, i_level, psz_fmt, arg );
+ va_end( arg );
+ }
+}
+
+static void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg )
+{
+ char *psz_prefix;
+ switch( i_level )
+ {
+ case X264_LOG_ERROR:
+ psz_prefix = "error";
+ break;
+ case X264_LOG_WARNING:
+ psz_prefix = "warning";
+ break;
+ case X264_LOG_INFO:
+ psz_prefix = "info";
+ break;
+ case X264_LOG_DEBUG:
+ psz_prefix = "debug";
+ break;
+ default:
+ psz_prefix = "unknown";
+ break;
+ }
+ fprintf( stderr, "x264 [%s]: ", psz_prefix );
+ vfprintf( stderr, psz_fmt, arg );
+}
+
+/****************************************************************************
+ * x264_picture_alloc:
+ ****************************************************************************/
+void x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height )
+{
+ pic->i_type = X264_TYPE_AUTO;
+ pic->i_qpplus1 = 0;
+ pic->img.i_csp = i_csp;
+ switch( i_csp & X264_CSP_MASK )
+ {
+ case X264_CSP_I420:
+ case X264_CSP_YV12:
+ pic->img.i_plane = 3;
+ pic->img.plane[0] = x264_malloc( 3 * i_width * i_height / 2 );
+ pic->img.plane[1] = pic->img.plane[0] + i_width * i_height;
+ pic->img.plane[2] = pic->img.plane[1] + i_width * i_height / 4;
+ pic->img.i_stride[0] = i_width;
+ pic->img.i_stride[1] = i_width / 2;
+ pic->img.i_stride[2] = i_width / 2;
+ break;
+
+ case X264_CSP_I422:
+ pic->img.i_plane = 3;
+ pic->img.plane[0] = x264_malloc( 2 * i_width * i_height );
+ pic->img.plane[1] = pic->img.plane[0] + i_width * i_height;
+ pic->img.plane[2] = pic->img.plane[1] + i_width * i_height / 2;
+ pic->img.i_stride[0] = i_width;
+ pic->img.i_stride[1] = i_width / 2;
+ pic->img.i_stride[2] = i_width / 2;
+ break;
+
+ case X264_CSP_I444:
+ pic->img.i_plane = 3;
+ pic->img.plane[0] = x264_malloc( 3 * i_width * i_height );
+ pic->img.plane[1] = pic->img.plane[0] + i_width * i_height;
+ pic->img.plane[2] = pic->img.plane[1] + i_width * i_height;
+ pic->img.i_stride[0] = i_width;
+ pic->img.i_stride[1] = i_width;
+ pic->img.i_stride[2] = i_width;
+ break;
+
+ case X264_CSP_YUYV:
+ pic->img.i_plane = 1;
+ pic->img.plane[0] = x264_malloc( 2 * i_width * i_height );
+ pic->img.i_stride[0] = 2 * i_width;
+ break;
+
+ case X264_CSP_RGB:
+ case X264_CSP_BGR:
+ pic->img.i_plane = 1;
+ pic->img.plane[0] = x264_malloc( 3 * i_width * i_height );
+ pic->img.i_stride[0] = 3 * i_width;
+ break;
+
+ case X264_CSP_BGRA:
+ pic->img.i_plane = 1;
+ pic->img.plane[0] = x264_malloc( 4 * i_width * i_height );
+ pic->img.i_stride[0] = 4 * i_width;
+ break;
+
+ default:
+ fprintf( stderr, "invalid CSP\n" );
+ pic->img.i_plane = 0;
+ break;
+ }
+}
+
+/****************************************************************************
+ * x264_picture_clean:
+ ****************************************************************************/
+void x264_picture_clean( x264_picture_t *pic )
+{
+ x264_free( pic->img.plane[0] );
+
+ /* just to be safe */
+ memset( pic, 0, sizeof( x264_picture_t ) );
+}
+
+/****************************************************************************
+ * x264_nal_encode:
+ ****************************************************************************/
+int x264_nal_encode( void *p_data, int *pi_data, int b_annexeb, x264_nal_t *nal )
+{
+ uint8_t *dst = p_data;
+ uint8_t *src = nal->p_payload;
+ uint8_t *end = &nal->p_payload[nal->i_payload];
+
+ int i_count = 0;
+
+ /* FIXME this code doesn't check overflow */
+
+ if( b_annexeb )
+ {
+ /* long nal start code (we always use long ones)*/
+ *dst++ = 0x00;
+ *dst++ = 0x00;
+ *dst++ = 0x00;
+ *dst++ = 0x01;
+ }
+
+ /* nal header */
+ *dst++ = ( 0x00 << 7 ) | ( nal->i_ref_idc << 5 ) | nal->i_type;
+
+ while( src < end )
+ {
+ if( i_count == 2 && *src <= 0x03 )
+ {
+ *dst++ = 0x03;
+ i_count = 0;
+ }
+ if( *src == 0 )
+ {
+ i_count++;
+ }
+ else
+ {
+ i_count = 0;
+ }
+ *dst++ = *src++;
+ }
+ *pi_data = dst - (uint8_t*)p_data;
+
+ return *pi_data;
+}
+
+/****************************************************************************
+ * x264_nal_decode:
+ ****************************************************************************/
+int x264_nal_decode( x264_nal_t *nal, void *p_data, int i_data )
+{
+ uint8_t *src = p_data;
+ uint8_t *end = &src[i_data];
+ uint8_t *dst = nal->p_payload;
+
+ nal->i_type = src[0]&0x1f;
+ nal->i_ref_idc = (src[0] >> 5)&0x03;
+
+ src++;
+
+ while( src < end )
+ {
+ if( src < end - 3 && src[0] == 0x00 && src[1] == 0x00 && src[2] == 0x03 )
+ {
+ *dst++ = 0x00;
+ *dst++ = 0x00;
+
+ src += 3;
+ continue;
+ }
+ *dst++ = *src++;
+ }
+
+ nal->i_payload = dst - (uint8_t*)p_data;
+ return 0;
+}
+
+
+
+/****************************************************************************
+ * x264_malloc:
+ ****************************************************************************/
+void *x264_malloc( int i_size )
+{
+#ifdef SYS_MACOSX
+ /* Mac OS X always returns 16 bytes aligned memory */
+ return malloc( i_size );
+#elif defined( HAVE_MALLOC_H )
+ return memalign( 16, i_size );
+#else
+ uint8_t * buf;
+ uint8_t * align_buf;
+ buf = (uint8_t *) malloc( i_size + 15 + sizeof( void ** ) +
+ sizeof( int ) );
+ align_buf = buf + 15 + sizeof( void ** ) + sizeof( int );
+ align_buf -= (long) align_buf & 15;
+ *( (void **) ( align_buf - sizeof( void ** ) ) ) = buf;
+ *( (int *) ( align_buf - sizeof( void ** ) - sizeof( int ) ) ) = i_size;
+ return align_buf;
+#endif
+}
+
+/****************************************************************************
+ * x264_free:
+ ****************************************************************************/
+void x264_free( void *p )
+{
+ if( p )
+ {
+#if defined( HAVE_MALLOC_H ) || defined( SYS_MACOSX )
+ free( p );
+#else
+ free( *( ( ( void **) p ) - 1 ) );
+#endif
+ }
+}
+
+/****************************************************************************
+ * x264_realloc:
+ ****************************************************************************/
+void *x264_realloc( void *p, int i_size )
+{
+#ifdef HAVE_MALLOC_H
+ return realloc( p, i_size );
+#else
+ int i_old_size = 0;
+ uint8_t * p_new;
+ if( p )
+ {
+ i_old_size = *( (int*) ( (uint8_t*) p ) - sizeof( void ** ) -
+ sizeof( int ) );
+ }
+ p_new = x264_malloc( i_size );
+ if( i_old_size > 0 && i_size > 0 )
+ {
+ memcpy( p_new, p, ( i_old_size < i_size ) ? i_old_size : i_size );
+ }
+ x264_free( p );
+ return p_new;
+#endif
+}
+
--- /dev/null
+/*****************************************************************************
+ * common.h: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: common.h,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifndef _COMMON_H
+#define _COMMON_H 1
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdarg.h>
+
+#include "../x264.h"
+#include "bs.h"
+#include "set.h"
+#include "predict.h"
+#include "pixel.h"
+#include "mc.h"
+#include "frame.h"
+#include "dct.h"
+#include "cabac.h"
+#include "csp.h"
+
+/****************************************************************************
+ * Macros
+ ****************************************************************************/
+#define X264_MIN(a,b) ( (a)<(b) ? (a) : (b) )
+#define X264_MAX(a,b) ( (a)>(b) ? (a) : (b) )
+#define X264_ABS(a) ( (a)< 0 ? -(a) : (a) )
+
+/****************************************************************************
+ * Generals functions
+ ****************************************************************************/
+/* x264_malloc : will do or emulate a memalign
+ * XXX you HAVE TO use x264_free for buffer allocated
+ * with x264_malloc
+ */
+void *x264_malloc( int );
+void *x264_realloc( void *p, int i_size );
+void x264_free( void * );
+
+/* mdate: return the current date in microsecond */
+int64_t x264_mdate( void );
+
+/* log */
+void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... );
+
+static inline int x264_clip3( int v, int i_min, int i_max )
+{
+ return ( (v < i_min) ? i_min : (v > i_max) ? i_max : v );
+}
+
+static inline float x264_clip3f( float v, float f_min, float f_max )
+{
+ return ( (v < f_min) ? f_min : (v > f_max) ? f_max : v );
+}
+
+/****************************************************************************
+ *
+ ****************************************************************************/
+enum slice_type_e
+{
+ SLICE_TYPE_P = 0,
+ SLICE_TYPE_B = 1,
+ SLICE_TYPE_I = 2,
+ SLICE_TYPE_SP = 3,
+ SLICE_TYPE_SI = 4
+};
+
+typedef struct
+{
+ x264_sps_t *sps;
+ x264_pps_t *pps;
+
+ int i_type;
+ int i_first_mb;
+
+ int i_pps_id;
+
+ int i_frame_num;
+
+ int b_field_pic;
+ int b_bottom_field;
+
+ int i_idr_pic_id; /* -1 if nal_type != 5 */
+
+ int i_poc_lsb;
+ int i_delta_poc_bottom;
+
+ int i_delta_poc[2];
+ int i_redundant_pic_cnt;
+
+ int b_direct_spatial_mv_pred;
+
+ int b_num_ref_idx_override;
+ int i_num_ref_idx_l0_active;
+ int i_num_ref_idx_l1_active;
+
+ int i_cabac_init_idc;
+
+ int i_qp_delta;
+ int b_sp_for_swidth;
+ int i_qs_delta;
+
+ /* deblocking filter */
+ int i_disable_deblocking_filter_idc;
+ int i_alpha_c0_offset;
+ int i_beta_offset;
+
+} x264_slice_header_t;
+
+/* From ffmpeg
+ */
+#define X264_SCAN8_SIZE (6*8)
+#define X264_SCAN8_0 (4+1*8)
+
+static const int x264_scan8[16+2*4] =
+{
+ /* Luma */
+ 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,
+
+ /* Cb */
+ 1+1*8, 2+1*8,
+ 1+2*8, 2+2*8,
+
+ /* Cr */
+ 1+4*8, 2+4*8,
+ 1+5*8, 2+5*8,
+};
+/*
+ 0 1 2 3 4 5 6 7
+ 0
+ 1 B B L L L L
+ 2 B B L L L L
+ 3 L L L L
+ 4 R R L L L L
+ 5 R R
+*/
+
+#define X264_BFRAME_MAX 16
+
+typedef struct x264_ratecontrol_t x264_ratecontrol_t;
+typedef struct x264_vlc_table_t x264_vlc_table_t;
+
+struct x264_t
+{
+ /* encoder parameters */
+ x264_param_t param;
+
+ /* bitstream output */
+ struct
+ {
+ int i_nal;
+ x264_nal_t nal[3]; /* for now 3 is enought */
+ int i_bitstream; /* size of p_bitstream */
+ uint8_t *p_bitstream; /* will hold data for all nal */
+ bs_t bs;
+ } out;
+
+ /* frame number/poc */
+ int i_frame;
+ int i_poc;
+
+ int i_frame_offset; /* decoding only */
+ int i_frame_num; /* decoding only */
+ int i_poc_msb; /* decoding only */
+ int i_poc_lsb; /* decoding only */
+
+ /* We use only one SPS and one PPS */
+ x264_sps_t sps_array[32];
+ x264_sps_t *sps;
+ x264_pps_t pps_array[256];
+ x264_pps_t *pps;
+ int i_idr_pic_id;
+
+ /* Slice header */
+ x264_slice_header_t sh;
+
+ /* cabac context */
+ x264_cabac_t cabac;
+
+ struct
+ {
+ /* Frames to be encoded */
+ x264_frame_t *current[X264_BFRAME_MAX+1];
+ /* Temporary buffer (eg B frames pending until we reach the I/P) */
+ x264_frame_t *next[X264_BFRAME_MAX+1];
+ /* Unused frames */
+ x264_frame_t *unused[X264_BFRAME_MAX+1];
+
+ /* frames used for reference +1 for decoding */
+ x264_frame_t *reference[16+1];
+
+ int i_last_idr; /* How many I non IDR frames from last IDR */
+ int i_last_i; /* How many P/B frames from last I */
+
+ int i_input; /* Number of input frames already accepted */
+ } frames;
+
+ /* current frame being encoded */
+ x264_frame_t *fenc;
+
+ /* frame being reconstructed */
+ x264_frame_t *fdec;
+
+ /* references lists */
+ int i_ref0;
+ x264_frame_t *fref0[16]; /* ref list 0 */
+ int i_ref1;
+ x264_frame_t *fref1[16]; /* ref list 1 */
+
+
+
+ /* Current MB DCT coeffs */
+ struct
+ {
+ DECLARE_ALIGNED( int, luma16x16_dc[16], 16 );
+ DECLARE_ALIGNED( int, chroma_dc[2][4], 16 );
+ union
+ {
+ DECLARE_ALIGNED( int, residual_ac[15], 16 );
+ DECLARE_ALIGNED( int, luma4x4[16], 16 );
+ } block[16+8];
+ } dct;
+
+ /* MB table and cache for current frame/mb */
+ struct
+ {
+ /* Strides */
+ int i_mb_stride;
+
+ /* Current index */
+ int i_mb_x;
+ int i_mb_y;
+ int i_mb_xy;
+
+ unsigned int i_neighbour;
+
+ /* mb table */
+ int8_t *type; /* mb type */
+ int8_t *qp; /* mb qp */
+ int16_t *cbp; /* mb cbp: 0x0?: luma, 0x?0: chroma, 0x100: luma dc, 0x0200 and 0x0400: chroma dc (all set for PCM)*/
+ int8_t (*intra4x4_pred_mode)[7]; /* intra4x4 pred mode. for non I4x4 set to I_PRED_4x4_DC(2) */
+ uint8_t (*non_zero_count)[16+4+4]; /* nzc. for I_PCM set to 16 */
+ int8_t *chroma_pred_mode; /* chroma_pred_mode. cabac only. for non intra I_PRED_CHROMA_DC(0) */
+ int16_t (*mv[2])[2]; /* mb mv. set to 0 for intra mb */
+ int16_t (*mvd[2])[2]; /* mb mv difference with predict. set to 0 if intra. cabac only */
+ int8_t *ref[2]; /* mb ref. set to -1 if non used (intra or Lx only) */
+ int16_t (*mvr[2][16])[2]; /* mb mv for each possible ref */
+
+ /* current value */
+ int i_type;
+ int i_partition;
+ int i_sub_partition[4];
+
+ int i_cbp_luma;
+ int i_cbp_chroma;
+
+ int i_intra16x16_pred_mode;
+ int i_chroma_pred_mode;
+
+ struct
+ {
+ /* pointer over mb of the frame to be compressed */
+ uint8_t *p_fenc[3];
+
+ /* pointer over mb of the frame to be reconstrucated */
+ uint8_t *p_fdec[3];
+
+ /* pointer over mb of the references */
+ uint8_t *p_fref[2][16][3];
+
+ /* common stride */
+ int i_stride[3];
+ } pic;
+
+ /* cache */
+ struct
+ {
+ /* real intra4x4_pred_mode if I_4X4, I_PRED_4x4_DC if mb available, -1 if not */
+ int intra4x4_pred_mode[X264_SCAN8_SIZE];
+
+ /* i_non_zero_count if availble else 0x80 */
+ int non_zero_count[X264_SCAN8_SIZE];
+
+ /* -1 if unused, -2 if unavaible */
+ int8_t ref[2][X264_SCAN8_SIZE];
+
+ /* 0 if non avaible */
+ int16_t mv[2][X264_SCAN8_SIZE][2];
+ int16_t mvd[2][X264_SCAN8_SIZE][2];
+ } cache;
+
+ /* */
+ int i_last_qp; /* last qp */
+ int i_last_dqp; /* last delta qp */
+
+ } mb;
+
+ /* rate control encoding only */
+ x264_ratecontrol_t *rc;
+
+ int i_last_inter_size;
+ int i_last_intra_size;
+ int i_last_intra_qp;
+
+ /* stats */
+ struct
+ {
+ /* Current frame stats */
+ struct
+ {
+ /* Headers bits (MV+Ref+MB Block Type */
+ int i_hdr_bits;
+ /* Texture bits (Intra/Predicted) */
+ int i_itex_bits;
+ int i_ptex_bits;
+ /* ? */
+ int i_misc_bits;
+ /* MB type counts */
+ int i_mb_count[18];
+ int i_mb_count_p;
+ int i_mb_count_skip;
+ /* Estimated (SATD) cost as Intra/Predicted frame */
+ /* XXX: both omit the cost of MBs coded as P_SKIP */
+ int i_intra_cost;
+ int i_inter_cost;
+ } frame;
+
+ /* Cummulated stats */
+
+ /* per slice info */
+ int i_slice_count[5];
+ int64_t i_slice_size[5];
+ int i_slice_qp[5];
+ /* */
+ int64_t i_sqe_global[5];
+ float f_psnr_average[5];
+ float f_psnr_mean_y[5];
+ float f_psnr_mean_u[5];
+ float f_psnr_mean_v[5];
+ /* */
+ int64_t i_mb_count[5][18];
+
+ } stat;
+
+ /* CPU functions dependants */
+ x264_predict_t predict_16x16[4+3];
+ x264_predict_t predict_8x8[4+3];
+ x264_predict_t predict_4x4[9+3];
+
+ x264_pixel_function_t pixf;
+ x264_mc_function_t mc[2];
+ x264_dct_function_t dctf;
+ x264_csp_function_t csp;
+
+ /* vlc table for decoding purpose only */
+ x264_vlc_table_t *x264_coeff_token_lookup[5];
+ x264_vlc_table_t *x264_level_prefix_lookup;
+ x264_vlc_table_t *x264_total_zeros_lookup[15];
+ x264_vlc_table_t *x264_total_zeros_dc_lookup[3];
+ x264_vlc_table_t *x264_run_before_lookup[7];
+};
+
+#endif
+
--- /dev/null
+/*****************************************************************************
+ * cpu.c: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: cpu.c,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "../x264.h"
+#include "cpu.h"
+
+#ifdef ARCH_X86
+extern int x264_cpu_cpuid_test( void );
+extern uint32_t x264_cpu_cpuid( uint32_t op, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx );
+extern void x264_emms( void );
+
+uint32_t x264_cpu_detect( void )
+{
+ uint32_t cpu = 0;
+
+ uint32_t eax, ebx, ecx, edx;
+ int b_amd;
+
+
+ if( !x264_cpu_cpuid_test() )
+ {
+ /* No cpuid */
+ return 0;
+ }
+
+ x264_cpu_cpuid( 0, &eax, &ebx, &ecx, &edx);
+ if( eax == 0 )
+ {
+ return 0;
+ }
+ b_amd = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
+
+ x264_cpu_cpuid( 1, &eax, &ebx, &ecx, &edx );
+ if( (edx&0x00800000) == 0 )
+ {
+ /* No MMX */
+ return 0;
+ }
+ cpu = X264_CPU_MMX;
+ if( (edx&0x02000000) )
+ {
+ /* SSE - identical to AMD MMX extensions */
+ cpu |= X264_CPU_MMXEXT|X264_CPU_SSE;
+ }
+ if( (edx&0x04000000) )
+ {
+ /* Is it OK ? */
+ cpu |= X264_CPU_SSE2;
+ }
+
+ x264_cpu_cpuid( 0x80000000, &eax, &ebx, &ecx, &edx );
+ if( eax < 0x80000001 )
+ {
+ /* no extended capabilities */
+ return cpu;
+ }
+
+ x264_cpu_cpuid( 0x80000001, &eax, &ebx, &ecx, &edx );
+ if( edx&0x80000000 )
+ {
+ cpu |= X264_CPU_3DNOW;
+ }
+ if( b_amd && (edx&0x00400000) )
+ {
+ /* AMD MMX extensions */
+ cpu |= X264_CPU_MMXEXT;
+ }
+
+ return cpu;
+}
+
+void x264_cpu_restore( uint32_t cpu )
+{
+ if( cpu&(X264_CPU_MMX|X264_CPU_MMXEXT|X264_CPU_3DNOW|X264_CPU_3DNOWEXT) )
+ {
+ x264_emms();
+ }
+}
+
+
+#if 0
+/*
+ * XXX: adapted from libmpeg2 */
+#if 0
+#define cpuid(op,eax,ebx,ecx,edx) \
+ __asm__ ("push %%ebx\n\t" \
+ "cpuid\n\t" \
+ "movl %%ebx,%1\n\t" \
+ "pop %%ebx" \
+ : "=a" (eax), \
+ "=r" (ebx), \
+ "=c" (ecx), \
+ "=d" (edx) \
+ : "a" (op) \
+ : "cc")
+#endif
+
+uint32_t x264_cpu_detect( void )
+{
+ uint32_t cpu = 0;
+
+ uint32_t eax, ebx, ecx, edx;
+ int b_amd;
+
+
+ /* Test if cpuid is supported */
+ asm volatile(
+ "pushf\n"
+ "pushf\n"
+ "pop %0\n"
+ "movl %0,%1\n"
+ "xorl $0x200000,%0\n"
+ "push %0\n"
+ "popf\n"
+ "pushf\n"
+ "pop %0\n"
+ "popf\n"
+ : "=r" (eax), "=r" (ebx) : : "cc");
+
+ if( eax == ebx )
+ {
+ /* No cpuid */
+ return 0;
+ }
+
+ cpuid( 0, eax, ebx, ecx, edx);
+ if( eax == 0 )
+ {
+ return 0;
+ }
+ b_amd = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
+
+ cpuid( 1, eax, ebx, ecx, edx );
+ if( (edx&0x00800000) == 0 )
+ {
+ /* No MMX */
+ return 0;
+ }
+ cpu = X264_CPU_MMX;
+ if( (edx&0x02000000) )
+ {
+ /* SSE - identical to AMD MMX extensions */
+ cpu |= X264_CPU_MMXEXT|X264_CPU_SSE;
+ }
+ if( (edx&0x04000000) )
+ {
+ /* Is it OK ? */
+ cpu |= X264_CPU_SSE2;
+ }
+
+ cpuid( 0x80000000, eax, ebx, ecx, edx );
+ if( eax < 0x80000001 )
+ {
+ /* no extended capabilities */
+ return cpu;
+ }
+
+ cpuid( 0x80000001, eax, ebx, ecx, edx );
+ if( edx&0x80000000 )
+ {
+ cpu |= X264_CPU_3DNOW;
+ }
+ if( b_amd && (edx&0x00400000) )
+ {
+ /* AMD MMX extensions */
+ cpu |= X264_CPU_MMXEXT;
+ }
+
+ return cpu;
+}
+#endif
+
+#elif defined( ARCH_PPC )
+
+#ifdef SYS_MACOSX
+#include <sys/sysctl.h>
+uint32_t x264_cpu_detect( void )
+{
+ /* Thank you VLC */
+ uint32_t cpu = 0;
+ int selectors[2] = { CTL_HW, HW_VECTORUNIT };
+ int has_altivec = 0;
+ size_t length = sizeof( has_altivec );
+ int error = sysctl( selectors, 2, &has_altivec, &length, NULL, 0 );
+
+ if( error == 0 && has_altivec != 0 )
+ {
+ cpu |= X264_CPU_ALTIVEC;
+ }
+
+ return cpu;
+}
+
+#elif defined( SYS_LINUX )
+uint32_t x264_cpu_detect( void )
+{
+ /* FIXME (Linux PPC) */
+ return X264_CPU_ALTIVEC;
+}
+#endif
+
+void x264_cpu_restore( uint32_t cpu )
+{
+}
+
+#else
+
+uint32_t x264_cpu_detect( void )
+{
+ return 0;
+}
+
+void x264_cpu_restore( uint32_t cpu )
+{
+}
+
+#endif
+
--- /dev/null
+/*****************************************************************************
+ * cpu.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: cpu.h,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifndef _CPU_H
+#define _CPU_H 1
+
+uint32_t x264_cpu_detect( void );
+
+/* probably MMX(EXT) centric but .... */
+void x264_cpu_restore( uint32_t cpu );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * csp.c: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2004 Laurent Aimar
+ * $Id: csp.c,v 1.1 2004/06/03 19:27:06 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 "common.h"
+
+static inline void plane_copy( uint8_t *dst, int i_dst,
+ uint8_t *src, int i_src, int w, int h)
+{
+ for( ; h > 0; h-- )
+ {
+ memcpy( dst, src, w );
+ dst += i_dst;
+ src += i_src;
+ }
+}
+static inline void plane_copy_vflip( uint8_t *dst, int i_dst,
+ uint8_t *src, int i_src, int w, int h)
+{
+ plane_copy( dst, i_dst, src + (h -1)*i_src, -i_src, w, h );
+}
+
+static inline void plane_subsamplev2( uint8_t *dst, int i_dst,
+ uint8_t *src, int i_src, int w, int h)
+{
+ for( ; h > 0; h-- )
+ {
+ uint8_t *d = dst;
+ uint8_t *s = src;
+ int i;
+ for( i = 0; i < w; i++ )
+ {
+ *d++ = ( s[0] + s[i_src] + 1 ) >> 1;
+ s++;
+ }
+ dst += i_dst;
+ src += 2 * i_src;
+ }
+}
+
+static inline void plane_subsamplev2_vlip( uint8_t *dst, int i_dst,
+ uint8_t *src, int i_src, int w, int h)
+{
+ plane_subsamplev2( dst, i_dst, src + (2*h-1)*i_src, -i_src, w, h );
+}
+
+static inline void plane_subsamplehv2( uint8_t *dst, int i_dst,
+ uint8_t *src, int i_src, int w, int h)
+{
+ for( ; h > 0; h-- )
+ {
+ uint8_t *d = dst;
+ uint8_t *s = src;
+ int i;
+ for( i = 0; i < w; i++ )
+ {
+ *d++ = ( s[0] + s[1] + s[i_src] + s[i_src+1] + 1 ) >> 2;
+ s += 2;
+ }
+ dst += i_dst;
+ src += 2 * i_src;
+ }
+}
+
+static inline void plane_subsamplehv2_vlip( uint8_t *dst, int i_dst,
+ uint8_t *src, int i_src, int w, int h)
+{
+ plane_subsamplehv2( dst, i_dst, src + (2*h-1)*i_src, -i_src, w, h );
+}
+
+static void i420_to_i420( x264_frame_t *frm, x264_image_t *img,
+ int i_width, int i_height )
+{
+ if( img->i_csp & X264_CSP_VFLIP )
+ {
+ plane_copy_vflip( frm->plane[0], frm->i_stride[0],
+ img->plane[0], img->i_stride[0],
+ i_width, i_height );
+ plane_copy_vflip( frm->plane[1], frm->i_stride[1],
+ img->plane[1], img->i_stride[1],
+ i_width / 2, i_height / 2 );
+ plane_copy_vflip( frm->plane[2], frm->i_stride[2],
+ img->plane[2], img->i_stride[2],
+ i_width / 2, i_height / 2 );
+ }
+ else
+ {
+ plane_copy( frm->plane[0], frm->i_stride[0],
+ img->plane[0], img->i_stride[0],
+ i_width, i_height );
+ plane_copy( frm->plane[1], frm->i_stride[1],
+ img->plane[1], img->i_stride[1],
+ i_width / 2, i_height / 2 );
+ plane_copy( frm->plane[2], frm->i_stride[2],
+ img->plane[2], img->i_stride[2],
+ i_width / 2, i_height / 2 );
+ }
+}
+
+static void yv12_to_i420( x264_frame_t *frm, x264_image_t *img,
+ int i_width, int i_height )
+{
+ if( img->i_csp & X264_CSP_VFLIP )
+ {
+ plane_copy_vflip( frm->plane[0], frm->i_stride[0],
+ img->plane[0], img->i_stride[0],
+ i_width, i_height );
+ plane_copy_vflip( frm->plane[2], frm->i_stride[2],
+ img->plane[1], img->i_stride[1],
+ i_width / 2, i_height / 2 );
+ plane_copy_vflip( frm->plane[1], frm->i_stride[1],
+ img->plane[2], img->i_stride[2],
+ i_width / 2, i_height / 2 );
+ }
+ else
+ {
+ plane_copy( frm->plane[0], frm->i_stride[0],
+ img->plane[0], img->i_stride[0],
+ i_width, i_height );
+ plane_copy( frm->plane[2], frm->i_stride[2],
+ img->plane[1], img->i_stride[1],
+ i_width / 2, i_height / 2 );
+ plane_copy( frm->plane[1], frm->i_stride[1],
+ img->plane[2], img->i_stride[2],
+ i_width / 2, i_height / 2 );
+ }
+}
+
+static void i422_to_i420( x264_frame_t *frm, x264_image_t *img,
+ int i_width, int i_height )
+{
+ if( img->i_csp & X264_CSP_VFLIP )
+ {
+ plane_copy_vflip( frm->plane[0], frm->i_stride[0],
+ img->plane[0], img->i_stride[0],
+ i_width, i_height );
+
+ plane_subsamplev2_vlip( frm->plane[1], frm->i_stride[1],
+ img->plane[1], img->i_stride[1],
+ i_width / 2, i_height / 2 );
+ plane_subsamplev2_vlip( frm->plane[2], frm->i_stride[2],
+ img->plane[2], img->i_stride[2],
+ i_width / 2, i_height / 2 );
+ }
+ else
+ {
+ plane_copy( frm->plane[0], frm->i_stride[0],
+ img->plane[0], img->i_stride[0],
+ i_width, i_height );
+
+ plane_subsamplev2( frm->plane[1], frm->i_stride[1],
+ img->plane[1], img->i_stride[1],
+ i_width / 2, i_height / 2 );
+ plane_subsamplev2( frm->plane[2], frm->i_stride[2],
+ img->plane[2], img->i_stride[2],
+ i_width / 2, i_height / 2 );
+ }
+}
+
+static void i444_to_i420( x264_frame_t *frm, x264_image_t *img,
+ int i_width, int i_height )
+{
+ if( img->i_csp & X264_CSP_VFLIP )
+ {
+ plane_copy_vflip( frm->plane[0], frm->i_stride[0],
+ img->plane[0], img->i_stride[0],
+ i_width, i_height );
+
+ plane_subsamplehv2_vlip( frm->plane[1], frm->i_stride[1],
+ img->plane[1], img->i_stride[1],
+ i_width / 2, i_height / 2 );
+ plane_subsamplehv2_vlip( frm->plane[2], frm->i_stride[2],
+ img->plane[2], img->i_stride[2],
+ i_width / 2, i_height / 2 );
+ }
+ else
+ {
+ plane_copy( frm->plane[0], frm->i_stride[0],
+ img->plane[0], img->i_stride[0],
+ i_width, i_height );
+
+ plane_subsamplehv2( frm->plane[1], frm->i_stride[1],
+ img->plane[1], img->i_stride[1],
+ i_width / 2, i_height / 2 );
+ plane_subsamplehv2( frm->plane[2], frm->i_stride[2],
+ img->plane[2], img->i_stride[2],
+ i_width / 2, i_height / 2 );
+ }
+}
+static void yuyv_to_i420( x264_frame_t *frm, x264_image_t *img,
+ int i_width, int i_height )
+{
+ uint8_t *src = img->plane[0];
+ int i_src= img->i_stride[0];
+
+ uint8_t *y = frm->plane[0];
+ uint8_t *u = frm->plane[1];
+ uint8_t *v = frm->plane[2];
+
+ if( img->i_csp & X264_CSP_VFLIP )
+ {
+ src += ( i_height - 1 ) * i_src;
+ i_src = -i_src;
+ }
+
+ for( ; i_height > 0; i_height -= 2 )
+ {
+ uint8_t *ss = src;
+ uint8_t *yy = y;
+ uint8_t *uu = u;
+ uint8_t *vv = v;
+ int w;
+
+ for( w = i_width; w > 0; w -= 2 )
+ {
+ *yy++ = ss[0];
+ *yy++ = ss[2];
+
+ *uu++ = ( ss[1] + ss[1+i_src] + 1 ) >> 1;
+ *vv++ = ( ss[3] + ss[3+i_src] + 1 ) >> 1;
+
+ ss += 4;
+ }
+ src += i_src;
+ y += frm->i_stride[0];
+ u += frm->i_stride[1];
+ v += frm->i_stride[2];
+
+ ss = src;
+ yy = y;
+ for( w = i_width; w > 0; w -= 2 )
+ {
+ *yy++ = ss[0];
+ *yy++ = ss[2];
+ ss += 4;
+ }
+ src += i_src;
+ y += frm->i_stride[0];
+ }
+}
+
+/* Same value than in XviD */
+#define BITS 8
+#define FIX(f) ((int)((f) * (1 << BITS) + 0.5))
+
+#define Y_R FIX(0.257)
+#define Y_G FIX(0.504)
+#define Y_B FIX(0.098)
+#define Y_ADD 16
+
+#define U_R FIX(0.148)
+#define U_G FIX(0.291)
+#define U_B FIX(0.439)
+#define U_ADD 128
+
+#define V_R FIX(0.439)
+#define V_G FIX(0.368)
+#define V_B FIX(0.071)
+#define V_ADD 128
+#define RGB_TO_I420( name, POS_R, POS_G, POS_B, S_RGB ) \
+static void name( x264_frame_t *frm, x264_image_t *img, \
+ int i_width, int i_height ) \
+{ \
+ uint8_t *src = img->plane[0]; \
+ int i_src= img->i_stride[0]; \
+ int i_y = frm->i_stride[0]; \
+ uint8_t *y = frm->plane[0]; \
+ uint8_t *u = frm->plane[1]; \
+ uint8_t *v = frm->plane[2]; \
+ \
+ if( img->i_csp & X264_CSP_VFLIP ) \
+ { \
+ src += ( i_height - 1 ) * i_src; \
+ i_src = -i_src; \
+ } \
+ \
+ for( ; i_height > 0; i_height -= 2 ) \
+ { \
+ uint8_t *ss = src; \
+ uint8_t *yy = y; \
+ uint8_t *uu = u; \
+ uint8_t *vv = v; \
+ int w; \
+ \
+ for( w = i_width; w > 0; w -= 2 ) \
+ { \
+ int cr = 0,cg = 0,cb = 0; \
+ int r, g, b; \
+ \
+ /* Luma */ \
+ cr = r = ss[POS_R]; \
+ cg = g = ss[POS_G]; \
+ cb = b = ss[POS_B]; \
+ \
+ yy[0] = Y_ADD + ((Y_R * r + Y_G * g + Y_B * b) >> BITS); \
+ \
+ cr+= r = ss[POS_R+i_src]; \
+ cg+= g = ss[POS_G+i_src]; \
+ cb+= b = ss[POS_B+i_src]; \
+ yy[i_y] = Y_ADD + ((Y_R * r + Y_G * g + Y_B * b) >> BITS); \
+ yy++; \
+ ss += S_RGB; \
+ \
+ cr+= r = ss[POS_R]; \
+ cg+= g = ss[POS_G]; \
+ cb+= b = ss[POS_B]; \
+ \
+ yy[0] = Y_ADD + ((Y_R * r + Y_G * g + Y_B * b) >> BITS); \
+ \
+ cr+= r = ss[POS_R+i_src]; \
+ cg+= g = ss[POS_G+i_src]; \
+ cb+= b = ss[POS_B+i_src]; \
+ yy[i_y] = Y_ADD + ((Y_R * r + Y_G * g + Y_B * b) >> BITS); \
+ yy++; \
+ ss += S_RGB; \
+ \
+ /* Chroma */ \
+ *uu++ = (uint8_t)(U_ADD + ((-U_R * cr - U_G * cg + U_B * cb) >> (BITS+2)) ); \
+ *vv++ = (uint8_t)(V_ADD + (( V_R * cr - V_G * cg - V_B * cb) >> (BITS+2)) ); \
+ } \
+ \
+ src += 2*i_src; \
+ y += 2*frm->i_stride[0]; \
+ u += frm->i_stride[1]; \
+ v += frm->i_stride[2]; \
+ } \
+}
+
+RGB_TO_I420( rgb_to_i420, 0, 1, 2, 3 );
+RGB_TO_I420( bgr_to_i420, 2, 1, 0, 3 );
+RGB_TO_I420( bgra_to_i420, 2, 1, 0, 4 );
+
+void x264_csp_init( int cpu, int i_csp, x264_csp_function_t *pf )
+{
+ switch( i_csp )
+ {
+ case X264_CSP_I420:
+ pf->i420 = i420_to_i420;
+ pf->i422 = i422_to_i420;
+ pf->i444 = i444_to_i420;
+ pf->yv12 = yv12_to_i420;
+ pf->yuyv = yuyv_to_i420;
+ pf->rgb = rgb_to_i420;
+ pf->bgr = bgr_to_i420;
+ pf->bgra = bgra_to_i420;
+ break;
+
+ default:
+ /* For now, can't happen */
+ fprintf( stderr, "arg in x264_csp_init\n" );
+ exit( -1 );
+ break;
+ }
+}
+
--- /dev/null
+/*****************************************************************************
+ * csp.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2004 Laurent Aimar
+ * $Id: csp.h,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifndef _CSP_H
+#define _CSP_H 1
+
+typedef struct
+{
+ void (*i420)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
+ void (*i422)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
+ void (*i444)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
+ void (*yv12)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
+ void (*yuyv)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
+ void (*rgb )( x264_frame_t *, x264_image_t *, int i_width, int i_height );
+ void (*bgr )( x264_frame_t *, x264_image_t *, int i_width, int i_height );
+ void (*bgra)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
+} x264_csp_function_t;
+
+
+void x264_csp_init( int cpu, int i_csp, x264_csp_function_t *pf );
+
+#endif
+
--- /dev/null
+/*****************************************************************************
+ * dct.c: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: dct.c,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "x264.h"
+
+#include "dct.h"
+#ifdef HAVE_MMXEXT
+# include "i386/dct.h"
+#endif
+
+
+static inline int clip_uint8( int a )
+{
+ if (a&(~255))
+ return (-a)>>31;
+ else
+ return a;
+}
+
+/*
+ * XXX For all dct dc : input could be equal to output so ...
+ */
+
+static void dct2x2dc( int16_t d[2][2] )
+{
+ int tmp[2][2];
+
+ tmp[0][0] = d[0][0] + d[0][1];
+ tmp[1][0] = d[0][0] - d[0][1];
+ tmp[0][1] = d[1][0] + d[1][1];
+ tmp[1][1] = d[1][0] - d[1][1];
+
+ d[0][0] = tmp[0][0] + tmp[0][1];
+ d[0][1] = tmp[1][0] + tmp[1][1];
+ d[1][0] = tmp[0][0] - tmp[0][1];
+ d[1][1] = tmp[1][0] - tmp[1][1];
+}
+
+static void dct4x4dc( int16_t d[4][4] )
+{
+ int16_t tmp[4][4];
+ int s01, s23;
+ int d01, d23;
+ int i;
+
+ for( i = 0; i < 4; i++ )
+ {
+ s01 = d[i][0] + d[i][1];
+ d01 = d[i][0] - d[i][1];
+ s23 = d[i][2] + d[i][3];
+ d23 = d[i][2] - d[i][3];
+
+ tmp[0][i] = s01 + s23;
+ tmp[1][i] = s01 - s23;
+ tmp[2][i] = d01 - d23;
+ tmp[3][i] = d01 + d23;
+ }
+
+ for( i = 0; i < 4; i++ )
+ {
+ s01 = tmp[i][0] + tmp[i][1];
+ d01 = tmp[i][0] - tmp[i][1];
+ s23 = tmp[i][2] + tmp[i][3];
+ d23 = tmp[i][2] - tmp[i][3];
+
+ d[0][i] = ( s01 + s23 + 1 ) >> 1;
+ d[1][i] = ( s01 - s23 + 1 ) >> 1;
+ d[2][i] = ( d01 - d23 + 1 ) >> 1;
+ d[3][i] = ( d01 + d23 + 1 ) >> 1;
+ }
+}
+
+static void idct4x4dc( int16_t d[4][4] )
+{
+ int16_t tmp[4][4];
+ int s01, s23;
+ int d01, d23;
+ int i;
+
+ for( i = 0; i < 4; i++ )
+ {
+ s01 = d[0][i] + d[1][i];
+ d01 = d[0][i] - d[1][i];
+ s23 = d[2][i] + d[3][i];
+ d23 = d[2][i] - d[3][i];
+
+ tmp[0][i] = s01 + s23;
+ tmp[1][i] = s01 - s23;
+ tmp[2][i] = d01 - d23;
+ tmp[3][i] = d01 + d23;
+ }
+
+ for( i = 0; i < 4; i++ )
+ {
+ s01 = tmp[i][0] + tmp[i][1];
+ d01 = tmp[i][0] - tmp[i][1];
+ s23 = tmp[i][2] + tmp[i][3];
+ d23 = tmp[i][2] - tmp[i][3];
+
+ d[i][0] = s01 + s23;
+ d[i][1] = s01 - s23;
+ d[i][2] = d01 - d23;
+ d[i][3] = d01 + d23;
+ }
+}
+
+static void sub4x4_dct( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
+{
+ int16_t d[4][4];
+ int16_t tmp[4][4];
+ int y, x;
+ int i;
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ d[y][x] = pix1[x] - pix2[x];
+ }
+ pix1 += i_pix1;
+ pix2 += i_pix2;
+ }
+
+ for( i = 0; i < 4; i++ )
+ {
+ const int s03 = d[i][0] + d[i][3];
+ const int s12 = d[i][1] + d[i][2];
+ const int d03 = d[i][0] - d[i][3];
+ const int d12 = d[i][1] - d[i][2];
+
+ tmp[0][i] = s03 + s12;
+ tmp[1][i] = 2*d03 + d12;
+ tmp[2][i] = s03 - s12;
+ tmp[3][i] = d03 - 2*d12;
+ }
+
+ for( i = 0; i < 4; i++ )
+ {
+ const int s03 = tmp[i][0] + tmp[i][3];
+ const int s12 = tmp[i][1] + tmp[i][2];
+ const int d03 = tmp[i][0] - tmp[i][3];
+ const int d12 = tmp[i][1] - tmp[i][2];
+
+ dct[0][i] = s03 + s12;
+ dct[1][i] = 2*d03 + d12;
+ dct[2][i] = s03 - s12;
+ dct[3][i] = d03 - 2*d12;
+ }
+}
+
+static void sub8x8_dct( int16_t dct[4][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
+{
+ sub4x4_dct( dct[0], &pix1[0], i_pix1, &pix2[0], i_pix2 );
+ sub4x4_dct( dct[1], &pix1[4], i_pix1, &pix2[4], i_pix2 );
+ sub4x4_dct( dct[2], &pix1[4*i_pix1+0], i_pix1, &pix2[4*i_pix2+0], i_pix2 );
+ sub4x4_dct( dct[3], &pix1[4*i_pix1+4], i_pix1, &pix2[4*i_pix2+4], i_pix2 );
+}
+
+static void sub16x16_dct( int16_t dct[16][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
+{
+ sub8x8_dct( &dct[ 0], pix1, i_pix1, pix2, i_pix2 );
+ sub8x8_dct( &dct[ 4], &pix1[8], i_pix1, &pix2[8], i_pix2 );
+ sub8x8_dct( &dct[ 8], &pix1[8*i_pix1], i_pix1, &pix2[8*i_pix2], i_pix2 );
+ sub8x8_dct( &dct[12], &pix1[8*i_pix1+8], i_pix1, &pix2[8*i_pix2+8], i_pix2 );
+}
+
+
+static void add4x4_idct( uint8_t *p_dst, int i_dst, int16_t dct[4][4] )
+{
+ int16_t d[4][4];
+ int16_t tmp[4][4];
+ int x, y;
+ int i;
+
+ for( i = 0; i < 4; i++ )
+ {
+ const int s02 = dct[i][0] + dct[i][2];
+ const int d02 = dct[i][0] - dct[i][2];
+ const int s13 = dct[i][1] + (dct[i][3]>>1);
+ const int d13 = (dct[i][1]>>1) - dct[i][3];
+
+ tmp[i][0] = s02 + s13;
+ tmp[i][1] = d02 + d13;
+ tmp[i][2] = d02 - d13;
+ tmp[i][3] = s02 - s13;
+ }
+
+ for( i = 0; i < 4; i++ )
+ {
+ const int s02 = tmp[0][i] + tmp[2][i];
+ const int d02 = tmp[0][i] - tmp[2][i];
+ const int s13 = tmp[1][i] + (tmp[3][i]>>1);
+ const int d13 = (tmp[1][i]>>1) - tmp[3][i];
+
+ d[0][i] = ( s02 + s13 + 32 ) >> 6;
+ d[1][i] = ( d02 + d13 + 32 ) >> 6;
+ d[2][i] = ( d02 - d13 + 32 ) >> 6;
+ d[3][i] = ( s02 - s13 + 32 ) >> 6;
+ }
+
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ p_dst[x] = clip_uint8( p_dst[x] + d[y][x] );
+ }
+ p_dst += i_dst;
+ }
+}
+
+static void add8x8_idct( uint8_t *p_dst, int i_dst, int16_t dct[4][4][4] )
+{
+ add4x4_idct( p_dst, i_dst, dct[0] );
+ add4x4_idct( &p_dst[4], i_dst, dct[1] );
+ add4x4_idct( &p_dst[4*i_dst+0], i_dst, dct[2] );
+ add4x4_idct( &p_dst[4*i_dst+4], i_dst, dct[3] );
+}
+
+static void add16x16_idct( uint8_t *p_dst, int i_dst, int16_t dct[16][4][4] )
+{
+ add8x8_idct( &p_dst[0], i_dst, &dct[0] );
+ add8x8_idct( &p_dst[8], i_dst, &dct[4] );
+ add8x8_idct( &p_dst[8*i_dst], i_dst, &dct[8] );
+ add8x8_idct( &p_dst[8*i_dst+8], i_dst, &dct[12] );
+}
+
+
+
+/****************************************************************************
+ * x264_dct_init:
+ ****************************************************************************/
+void x264_dct_init( int cpu, x264_dct_function_t *dctf )
+{
+ dctf->sub4x4_dct = sub4x4_dct;
+ dctf->add4x4_idct = add4x4_idct;
+
+ dctf->sub8x8_dct = sub8x8_dct;
+ dctf->add8x8_idct = add8x8_idct;
+
+ dctf->sub16x16_dct = sub16x16_dct;
+ dctf->add16x16_idct = add16x16_idct;
+
+ dctf->dct4x4dc = dct4x4dc;
+ dctf->idct4x4dc = idct4x4dc;
+
+ dctf->dct2x2dc = dct2x2dc;
+ dctf->idct2x2dc = dct2x2dc;
+
+#ifdef HAVE_MMXEXT
+ if( cpu&X264_CPU_MMXEXT )
+ {
+ dctf->sub4x4_dct = x264_sub4x4_dct_mmxext;
+ dctf->sub8x8_dct = x264_sub8x8_dct_mmxext;
+ dctf->sub16x16_dct = x264_sub16x16_dct_mmxext;
+
+ dctf->add4x4_idct = x264_add4x4_idct_mmxext;
+ dctf->add8x8_idct = x264_add8x8_idct_mmxext;
+ dctf->add16x16_idct = x264_add16x16_idct_mmxext;
+
+ dctf->dct4x4dc = x264_dct4x4dc_mmxext;
+ dctf->idct4x4dc = x264_idct4x4dc_mmxext;
+ }
+#endif
+}
+
--- /dev/null
+/*****************************************************************************
+ * dct.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: dct.h,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifndef _DCT_H
+#define _DCT_H 1
+
+typedef struct
+{
+ void (*sub4x4_dct) ( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
+ void (*add4x4_idct) ( uint8_t *p_dst, int i_dst, int16_t dct[4][4] );
+
+ void (*sub8x8_dct) ( int16_t dct[4][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
+ void (*add8x8_idct) ( uint8_t *p_dst, int i_dst, int16_t dct[4][4][4] );
+
+ void (*sub16x16_dct) ( int16_t dct[16][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
+ void (*add16x16_idct) ( uint8_t *p_dst, int i_dst, int16_t dct[16][4][4] );
+
+
+ void (*dct4x4dc) ( int16_t d[4][4] );
+ void (*idct4x4dc)( int16_t d[4][4] );
+
+ void (*dct2x2dc) ( int16_t d[2][2] );
+ void (*idct2x2dc)( int16_t d[2][2] );
+
+} x264_dct_function_t;
+
+void x264_dct_init( int cpu, x264_dct_function_t *dctf );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * frame.c: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: frame.c,v 1.1 2004/06/03 19:27:06 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 "common.h"
+#include "macroblock.h"
+
+x264_frame_t *x264_frame_new( x264_t *h )
+{
+ x264_frame_t *frame = x264_malloc( sizeof( x264_frame_t ) );
+ int i;
+
+ int i_stride;
+ int i_lines;
+
+ /* allocate frame data (+64 for extra data for me) */
+ i_stride = ( ( h->param.i_width + 15 )&0xfffff0 )+ 64;
+ i_lines = ( ( h->param.i_height + 15 )&0xfffff0 );
+
+ frame->i_plane = 3;
+ for( i = 0; i < 3; i++ )
+ {
+ int i_divh = 1;
+ int i_divw = 1;
+ if( i > 0 )
+ {
+ if( h->param.i_csp == X264_CSP_I420 )
+ i_divh = i_divw = 2;
+ else if( h->param.i_csp == X264_CSP_I422 )
+ i_divw = 2;
+ }
+ frame->i_stride[i] = i_stride / i_divw;
+ frame->i_lines[i] = i_lines / i_divh;
+ frame->buffer[i] = x264_malloc( frame->i_stride[i] *
+ ( frame->i_lines[i] + 64 / i_divh ) );
+
+ frame->plane[i] = ((uint8_t*)frame->buffer[i]) +
+ frame->i_stride[i] * 32 / i_divh + 32 / i_divw;
+ }
+ frame->i_stride[3] = 0;
+ frame->i_lines[3] = 0;
+ frame->buffer[3] = NULL;
+ frame->plane[3] = NULL;
+
+ frame->i_poc = -1;
+ frame->i_type = X264_TYPE_AUTO;
+ frame->i_qpplus1 = 0;
+ frame->i_pts = -1;
+ frame->i_frame = -1;
+
+ return frame;
+}
+
+void x264_frame_delete( x264_frame_t *frame )
+{
+ int i;
+ for( i = 0; i < frame->i_plane; i++ )
+ {
+ x264_free( frame->buffer[i] );
+ }
+ x264_free( frame );
+}
+
+void x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
+{
+ dst->i_type = src->i_type;
+ dst->i_qpplus1 = src->i_qpplus1;
+ dst->i_pts = src->i_pts;
+
+ switch( src->img.i_csp & X264_CSP_MASK )
+ {
+ case X264_CSP_I420:
+ h->csp.i420( dst, &src->img, h->param.i_width, h->param.i_height );
+ break;
+ case X264_CSP_YV12:
+ h->csp.yv12( dst, &src->img, h->param.i_width, h->param.i_height );
+ break;
+ case X264_CSP_I422:
+ h->csp.i422( dst, &src->img, h->param.i_width, h->param.i_height );
+ break;
+ case X264_CSP_I444:
+ h->csp.i444( dst, &src->img, h->param.i_width, h->param.i_height );
+ break;
+ case X264_CSP_YUYV:
+ h->csp.yuyv( dst, &src->img, h->param.i_width, h->param.i_height );
+ break;
+ case X264_CSP_RGB:
+ h->csp.rgb( dst, &src->img, h->param.i_width, h->param.i_height );
+ break;
+ case X264_CSP_BGR:
+ h->csp.bgr( dst, &src->img, h->param.i_width, h->param.i_height );
+ break;
+ case X264_CSP_BGRA:
+ h->csp.bgra( dst, &src->img, h->param.i_width, h->param.i_height );
+ break;
+
+ default:
+ x264_log( h, X264_LOG_ERROR, "Arg invalid CSP\n" );
+ break;
+ }
+}
+
+
+
+void x264_frame_expand_border( x264_frame_t *frame )
+{
+ int w;
+ int i, y;
+ for( i = 0; i < frame->i_plane; i++ )
+ {
+#define PPIXEL(x, y) ( frame->plane[i] + (x) +(y)*frame->i_stride[i] )
+ w = ( i == 0 ) ? 32 : 16;
+
+ for( y = 0; y < w; y++ )
+ {
+ /* upper band */
+ memcpy( PPIXEL(0,-y-1), PPIXEL(0,0), frame->i_stride[i] - 2 * w);
+ /* up left corner */
+ memset( PPIXEL(-w,-y-1 ), PPIXEL(0,0)[0], w );
+ /* up right corner */
+ memset( PPIXEL(frame->i_stride[i] - 2*w,-y-1), PPIXEL( frame->i_stride[i]-1-2*w,0)[0], w );
+
+ /* lower band */
+ memcpy( PPIXEL(0, frame->i_lines[i]+y), PPIXEL(0,frame->i_lines[i]-1), frame->i_stride[i] - 2 * w );
+ /* low left corner */
+ memset( PPIXEL(-w, frame->i_lines[i]+y), PPIXEL(0,frame->i_lines[i]-1)[0], w);
+ /* low right corner */
+ memset( PPIXEL(frame->i_stride[i]-2*w, frame->i_lines[i]+y), PPIXEL(frame->i_stride[i]-1-2*w,frame->i_lines[i]-1)[0], w);
+
+ }
+ for( y = 0; y < frame->i_lines[i]; y++ )
+ {
+ /* left band */
+ memset( PPIXEL( -w, y ), PPIXEL( 0, y )[0], w );
+ /* right band */
+ memset( PPIXEL( frame->i_stride[i]-2*w, y ), PPIXEL( frame->i_stride[i] - 1-2*w, y )[0], w );
+ }
+#undef PPIXEL
+ }
+}
+
+/* FIXME theses tables are duplicated with the ones in macroblock.c */
+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 i_chroma_qp_table[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
+};
+
+/* Deblocking filter (p153) */
+static const int i_alpha_table[52] =
+{
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 4, 4, 5, 6,
+ 7, 8, 9, 10, 12, 13, 15, 17, 20, 22,
+ 25, 28, 32, 36, 40, 45, 50, 56, 63, 71,
+ 80, 90,101,113,127,144,162,182,203,226,
+ 255, 255
+};
+static const int i_beta_table[52] =
+{
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 2, 2, 2, 3,
+ 3, 3, 3, 4, 4, 4, 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
+};
+static const int i_tc0_table[52][3] =
+{
+ { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
+ { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
+ { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 1 },
+ { 0, 0, 1 }, { 0, 0, 1 }, { 0, 0, 1 }, { 0, 1, 1 }, { 0, 1, 1 }, { 1, 1, 1 },
+ { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 2 }, { 1, 1, 2 },
+ { 1, 1, 2 }, { 1, 2, 3 }, { 1, 2, 3 }, { 2, 2, 3 }, { 2, 2, 4 }, { 2, 3, 4 },
+ { 2, 3, 4 }, { 3, 3, 5 }, { 3, 4, 6 }, { 3, 4, 6 }, { 4, 5, 7 }, { 4, 5, 8 },
+ { 4, 6, 9 }, { 5, 7,10 }, { 6, 8,11 }, { 6, 8,13 }, { 7,10,14 }, { 8,11,16 },
+ { 9,12,18 }, {10,13,20 }, {11,15,23 }, {13,17,25 }
+};
+
+/* From ffmpeg */
+static inline int clip_uint8( int a )
+{
+ if (a&(~255))
+ return (-a)>>31;
+ else
+ return a;
+}
+
+static inline void deblocking_filter_edgev( x264_t *h, uint8_t *pix, int i_pix_stride, int bS[4], int i_QP )
+{
+ int i, d;
+ const int i_index_a = x264_clip3( i_QP + h->sh.i_alpha_c0_offset, 0, 51 );
+ const int alpha = i_alpha_table[i_index_a];
+ const int beta = i_beta_table[x264_clip3( i_QP + h->sh.i_beta_offset, 0, 51 )];
+
+ for( i = 0; i < 4; i++ )
+ {
+ if( bS[i] == 0 )
+ {
+ pix += 4 * i_pix_stride;
+ continue;
+ }
+
+ if( bS[i] < 4 )
+ {
+ const int tc0 = i_tc0_table[i_index_a][bS[i] - 1];
+
+ /* 4px edge length */
+ for( d = 0; d < 4; d++ )
+ {
+ const int p0 = pix[-1];
+ const int p1 = pix[-2];
+ const int p2 = pix[-3];
+ const int q0 = pix[0];
+ const int q1 = pix[1];
+ const int q2 = pix[2];
+
+ if( abs( p0 - q0 ) < alpha &&
+ abs( p1 - p0 ) < beta &&
+ abs( q1 - q0 ) < beta )
+ {
+ int tc = tc0;
+ int i_delta;
+
+ if( abs( p2 - p0 ) < beta )
+ {
+ pix[-2] = p1 + x264_clip3( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
+ tc++;
+ }
+ if( abs( q2 - q0 ) < beta )
+ {
+ pix[1] = q1 + x264_clip3( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
+ tc++;
+ }
+
+ i_delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
+ pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */
+ pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
+ }
+ pix += i_pix_stride;
+ }
+ }
+ else
+ {
+ /* 4px edge length */
+ for( d = 0; d < 4; d++ )
+ {
+ const int p0 = pix[-1];
+ const int p1 = pix[-2];
+ const int p2 = pix[-3];
+
+ const int q0 = pix[0];
+ const int q1 = pix[1];
+ const int q2 = pix[2];
+
+ if( abs( p0 - q0 ) < alpha &&
+ abs( p1 - p0 ) < beta &&
+ abs( q1 - q0 ) < beta )
+ {
+ if( abs( p0 - q0 ) < (( alpha >> 2 ) + 2 ) )
+ {
+ if( abs( p2 - p0 ) < beta )
+ {
+ const int p3 = pix[-4];
+ /* p0', p1', p2' */
+ pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
+ pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
+ pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
+ }
+ else
+ {
+ /* p0' */
+ pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
+ }
+ if( abs( q2 - q0 ) < beta )
+ {
+ const int q3 = pix[3];
+ /* q0', q1', q2' */
+ pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
+ pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
+ pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
+ }
+ else
+ {
+ /* q0' */
+ pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
+ }
+ }
+ else
+ {
+ /* p0', q0' */
+ pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
+ pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
+ }
+ }
+ pix += i_pix_stride;
+ }
+ }
+ }
+}
+
+static inline void deblocking_filter_edgecv( x264_t *h, uint8_t *pix, int i_pix_stride, int bS[4], int i_QP )
+{
+ int i, d;
+ const int i_index_a = x264_clip3( i_QP + h->sh.i_alpha_c0_offset, 0, 51 );
+ const int alpha = i_alpha_table[i_index_a];
+ const int beta = i_beta_table[x264_clip3( i_QP + h->sh.i_beta_offset, 0, 51 )];
+
+ for( i = 0; i < 4; i++ )
+ {
+ if( bS[i] == 0 )
+ {
+ pix += 2 * i_pix_stride;
+ continue;
+ }
+
+ if( bS[i] < 4 )
+ {
+ const int tc = i_tc0_table[i_index_a][bS[i] - 1] + 1;
+ /* 2px edge length (because we use same bS than the one for luma) */
+ for( d = 0; d < 2; d++ )
+ {
+ const int p0 = pix[-1];
+ const int p1 = pix[-2];
+ const int q0 = pix[0];
+ const int q1 = pix[1];
+
+ if( abs( p0 - q0 ) < alpha &&
+ abs( p1 - p0 ) < beta &&
+ abs( q1 - q0 ) < beta )
+ {
+ const int i_delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
+
+ pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */
+ pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
+ }
+ pix += i_pix_stride;
+ }
+ }
+ else
+ {
+ /* 2px edge length (because we use same bS than the one for luma) */
+ for( d = 0; d < 2; d++ )
+ {
+ const int p0 = pix[-1];
+ const int p1 = pix[-2];
+ const int q0 = pix[0];
+ const int q1 = pix[1];
+
+ if( abs( p0 - q0 ) < alpha &&
+ abs( p1 - p0 ) < beta &&
+ abs( q1 - q0 ) < beta )
+ {
+ pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
+ pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
+ }
+ pix += i_pix_stride;
+ }
+ }
+ }
+}
+
+static inline void deblocking_filter_edgeh( x264_t *h, uint8_t *pix, int i_pix_stride, int bS[4], int i_QP )
+{
+ int i, d;
+ const int i_index_a = x264_clip3( i_QP + h->sh.i_alpha_c0_offset, 0, 51 );
+ const int alpha = i_alpha_table[i_index_a];
+ const int beta = i_beta_table[x264_clip3( i_QP + h->sh.i_beta_offset, 0, 51 )];
+
+ int i_pix_next = i_pix_stride;
+
+ for( i = 0; i < 4; i++ )
+ {
+ if( bS[i] == 0 )
+ {
+ pix += 4;
+ continue;
+ }
+
+ if( bS[i] < 4 )
+ {
+ const int tc0 = i_tc0_table[i_index_a][bS[i] - 1];
+ /* 4px edge length */
+ for( d = 0; d < 4; d++ )
+ {
+ const int p0 = pix[-i_pix_next];
+ const int p1 = pix[-2*i_pix_next];
+ const int p2 = pix[-3*i_pix_next];
+ const int q0 = pix[0];
+ const int q1 = pix[1*i_pix_next];
+ const int q2 = pix[2*i_pix_next];
+
+ if( abs( p0 - q0 ) < alpha &&
+ abs( p1 - p0 ) < beta &&
+ abs( q1 - q0 ) < beta )
+ {
+ int tc = tc0;
+ int i_delta;
+
+ if( abs( p2 - p0 ) < beta )
+ {
+ pix[-2*i_pix_next] = p1 + x264_clip3( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
+ tc++;
+ }
+ if( abs( q2 - q0 ) < beta )
+ {
+ pix[i_pix_next] = q1 + x264_clip3( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
+ tc++;
+ }
+
+ i_delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
+ pix[-i_pix_next] = clip_uint8( p0 + i_delta ); /* p0' */
+ pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
+ }
+ pix++;
+ }
+ }
+ else
+ {
+ /* 4px edge length */
+ for( d = 0; d < 4; d++ )
+ {
+ const int p0 = pix[-i_pix_next];
+ const int p1 = pix[-2*i_pix_next];
+ const int p2 = pix[-3*i_pix_next];
+ const int q0 = pix[0];
+ const int q1 = pix[1*i_pix_next];
+ const int q2 = pix[2*i_pix_next];
+
+ if( abs( p0 - q0 ) < alpha &&
+ abs( p1 - p0 ) < beta &&
+ abs( q1 - q0 ) < beta )
+ {
+ const int p3 = pix[-4*i_pix_next];
+ const int q3 = pix[ 3*i_pix_next];
+
+ if( abs( p0 - q0 ) < (( alpha >> 2 ) + 2 ) )
+ {
+ if( abs( p2 - p0 ) < beta )
+ {
+ /* p0', p1', p2' */
+ pix[-1*i_pix_next] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
+ pix[-2*i_pix_next] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
+ pix[-3*i_pix_next] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
+ }
+ else
+ {
+ /* p0' */
+ pix[-1*i_pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
+ }
+ if( abs( q2 - q0 ) < beta )
+ {
+ /* q0', q1', q2' */
+ pix[0*i_pix_next] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
+ pix[1*i_pix_next] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
+ pix[2*i_pix_next] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
+ }
+ else
+ {
+ /* q0' */
+ pix[0*i_pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
+ }
+ }
+ else
+ {
+ /* p0' */
+ pix[-1*i_pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
+ /* q0' */
+ pix[0*i_pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
+ }
+ }
+ pix++;
+ }
+
+ }
+ }
+}
+
+static inline void deblocking_filter_edgech( x264_t *h, uint8_t *pix, int i_pix_stride, int bS[4], int i_QP )
+{
+ int i, d;
+ const int i_index_a = x264_clip3( i_QP + h->sh.i_alpha_c0_offset, 0, 51 );
+ const int alpha = i_alpha_table[i_index_a];
+ const int beta = i_beta_table[x264_clip3( i_QP + h->sh.i_beta_offset, 0, 51 )];
+
+ int i_pix_next = i_pix_stride;
+
+ for( i = 0; i < 4; i++ )
+ {
+ if( bS[i] == 0 )
+ {
+ pix += 2;
+ continue;
+ }
+ if( bS[i] < 4 )
+ {
+ int tc = i_tc0_table[i_index_a][bS[i] - 1] + 1;
+ /* 2px edge length (see deblocking_filter_edgecv) */
+ for( d = 0; d < 2; d++ )
+ {
+ const int p0 = pix[-1*i_pix_next];
+ const int p1 = pix[-2*i_pix_next];
+ const int q0 = pix[0];
+ const int q1 = pix[1*i_pix_next];
+
+ if( abs( p0 - q0 ) < alpha &&
+ abs( p1 - p0 ) < beta &&
+ abs( q1 - q0 ) < beta )
+ {
+ int i_delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
+
+ pix[-i_pix_next] = clip_uint8( p0 + i_delta ); /* p0' */
+ pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
+ }
+ pix++;
+ }
+ }
+ else
+ {
+ /* 2px edge length (see deblocking_filter_edgecv) */
+ for( d = 0; d < 2; d++ )
+ {
+ const int p0 = pix[-1*i_pix_next];
+ const int p1 = pix[-2*i_pix_next];
+ const int q0 = pix[0];
+ const int q1 = pix[1*i_pix_next];
+
+ if( abs( p0 - q0 ) < alpha &&
+ abs( p1 - p0 ) < beta &&
+ abs( q1 - q0 ) < beta )
+ {
+ pix[-i_pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
+ pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
+ }
+ pix++;
+ }
+ }
+ }
+}
+
+void x264_frame_deblocking_filter( x264_t *h, int i_slice_type )
+{
+ const int s8x8 = 2 * h->mb.i_mb_stride;
+ const int s4x4 = 4 * h->mb.i_mb_stride;
+
+ int mb_y, mb_x;
+
+ for( mb_y = 0, mb_x = 0; mb_y < h->sps->i_mb_height; )
+ {
+ const int mb_xy = mb_y * h->mb.i_mb_stride + mb_x;
+ const int mb_8x8 = 2 * s8x8 * mb_y + 2 * mb_x;
+ const int mb_4x4 = 4 * s4x4 * mb_y + 4 * mb_x;
+ int i_edge;
+ int i_dir;
+
+ /* i_dir == 0 -> vertical edge
+ * i_dir == 1 -> horizontal edge */
+ for( i_dir = 0; i_dir < 2; i_dir++ )
+ {
+ int i_start;
+ int i_qp, i_qpn;
+
+ i_start = (( i_dir == 0 && mb_x != 0 ) || ( i_dir == 1 && mb_y != 0 ) ) ? 0 : 1;
+
+ for( i_edge = i_start; i_edge < 4; i_edge++ )
+ {
+ int mbn_xy = i_edge > 0 ? mb_xy : ( i_dir == 0 ? mb_xy - 1 : mb_xy - h->mb.i_mb_stride );
+ int mbn_8x8 = i_edge > 0 ? mb_8x8 : ( i_dir == 0 ? mb_8x8 - 2 : mb_8x8 - 2 * s8x8 );
+ int mbn_4x4 = i_edge > 0 ? mb_4x4 : ( i_dir == 0 ? mb_4x4 - 4 : mb_4x4 - 4 * s4x4 );
+
+ int bS[4]; /* filtering strength */
+
+ /* *** Get bS for each 4px for the current edge *** */
+ if( IS_INTRA( h->mb.type[mb_xy] ) || IS_INTRA( h->mb.type[mbn_xy] ) )
+ {
+ bS[0] = bS[1] = bS[2] = bS[3] = ( i_edge == 0 ? 4 : 3 );
+ }
+ else
+ {
+ int i;
+ for( i = 0; i < 4; i++ )
+ {
+ int x = i_dir == 0 ? i_edge : i;
+ int y = i_dir == 0 ? i : i_edge;
+ int xn = (x - (i_dir == 0 ? 1 : 0 ))&0x03;
+ int yn = (y - (i_dir == 0 ? 0 : 1 ))&0x03;
+
+ if( h->mb.non_zero_count[mb_xy][block_idx_xy[x][y]] != 0 ||
+ h->mb.non_zero_count[mbn_xy][block_idx_xy[xn][yn]] != 0 )
+ {
+ bS[i] = 2;
+ }
+ else if( i_slice_type == SLICE_TYPE_P )
+ {
+ if( h->mb.ref[0][mb_8x8+(x/2)+(y/2)*s8x8] != h->mb.ref[0][mbn_8x8+(xn/2)+(yn/2)*s8x8] ||
+ abs( h->mb.mv[0][mb_4x4+x+y*s4x4][0] - h->mb.mv[0][mbn_4x4+xn+yn*s4x4][0] ) >= 4 ||
+ abs( h->mb.mv[0][mb_4x4+x+y*s4x4][1] - h->mb.mv[0][mbn_4x4+xn+yn*s4x4][1] ) >= 4 )
+ {
+ bS[i] = 1;
+ }
+ else
+ {
+ bS[i] = 0;
+ }
+ }
+ else
+ {
+ /* FIXME */
+ x264_log( h, X264_LOG_ERROR, "deblocking filter doesn't work yet with B slice\n" );
+ return;
+ }
+ }
+ }
+
+ /* *** filter *** */
+ /* Y plane */
+ i_qp = h->mb.qp[mb_xy];
+ i_qpn= h->mb.qp[mbn_xy];
+
+ if( i_dir == 0 )
+ {
+ /* vertical edge */
+ deblocking_filter_edgev( h, &h->fdec->plane[0][16 * mb_y * h->fdec->i_stride[0]+ 16 * mb_x + 4 * i_edge],
+ h->fdec->i_stride[0], bS, (i_qp+i_qpn+1) >> 1);
+ if( (i_edge % 2) == 0 )
+ {
+ /* U/V planes */
+ int i_qpc = ( i_chroma_qp_table[x264_clip3( i_qp + h->pps->i_chroma_qp_index_offset, 0, 51 )] +
+ i_chroma_qp_table[x264_clip3( i_qpn + h->pps->i_chroma_qp_index_offset, 0, 51 )] + 1 ) >> 1;
+ deblocking_filter_edgecv( h, &h->fdec->plane[1][8*(mb_y*h->fdec->i_stride[1]+mb_x)+i_edge*2],
+ h->fdec->i_stride[1], bS, i_qpc );
+ deblocking_filter_edgecv( h, &h->fdec->plane[2][8*(mb_y*h->fdec->i_stride[2]+mb_x)+i_edge*2],
+ h->fdec->i_stride[2], bS, i_qpc );
+ }
+ }
+ else
+ {
+ /* horizontal edge */
+ deblocking_filter_edgeh( h, &h->fdec->plane[0][(16*mb_y + 4 * i_edge) * h->fdec->i_stride[0]+ 16 * mb_x],
+ h->fdec->i_stride[0], bS, (i_qp+i_qpn+1) >> 1 );
+ /* U/V planes */
+ if( ( i_edge % 2 ) == 0 )
+ {
+ int i_qpc = ( i_chroma_qp_table[x264_clip3( i_qp + h->pps->i_chroma_qp_index_offset, 0, 51 )] +
+ i_chroma_qp_table[x264_clip3( i_qpn + h->pps->i_chroma_qp_index_offset, 0, 51 )] + 1 ) >> 1;
+ deblocking_filter_edgech( h, &h->fdec->plane[1][8*(mb_y*h->fdec->i_stride[1]+mb_x)+i_edge*2*h->fdec->i_stride[1]],
+ h->fdec->i_stride[1], bS, i_qpc );
+ deblocking_filter_edgech( h, &h->fdec->plane[2][8*(mb_y*h->fdec->i_stride[2]+mb_x)+i_edge*2*h->fdec->i_stride[2]],
+ h->fdec->i_stride[2], bS, i_qpc );
+ }
+ }
+ }
+ }
+
+ /* newt mb */
+ mb_x++;
+ if( mb_x >= h->sps->i_mb_width )
+ {
+ mb_x = 0;
+ mb_y++;
+ }
+ }
+}
+
+
+
+
--- /dev/null
+/*****************************************************************************
+ * frame.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: frame.h,v 1.1 2004/06/03 19:27:06 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.
+ *****************************************************************************/
+
+#ifndef _FRAME_H
+#define _FRAME_H 1
+
+typedef struct
+{
+ /* */
+ int i_poc;
+ int i_type;
+ int i_qpplus1;
+ int64_t i_pts;
+ int i_frame; /* Presentation frame number */
+
+ /* YUV buffer */
+ int i_plane;
+ int i_stride[4];
+ int i_lines[4];
+ uint8_t *plane[4];
+
+ /* for unrestricted mv we allocate more data than needed
+ * allocated data are stored in buffer */
+ void *buffer[4];
+
+} x264_frame_t;
+
+x264_frame_t *x264_frame_new( x264_t *h );
+void x264_frame_delete( x264_frame_t *frame );
+
+void x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src );
+
+void x264_frame_expand_border( x264_frame_t *frame );
+
+void x264_frame_deblocking_filter( x264_t *h, int i_slice_type );
+
+#endif
--- /dev/null
+;*****************************************************************************
+;* cpu.asm: h264 encoder library
+;*****************************************************************************
+;* Copyright (C) 2003 x264 project
+;* $Id: cpu.asm,v 1.1 2004/06/03 19:27:07 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.
+;*****************************************************************************
+
+BITS 32
+
+;=============================================================================
+; Macros and other preprocessor constants
+;=============================================================================
+
+%macro cglobal 1
+ %ifdef PREFIX
+ global _%1
+ %define %1 _%1
+ %else
+ global %1
+ %endif
+%endmacro
+
+;=============================================================================
+; Code
+;=============================================================================
+
+SECTION .text
+
+cglobal x264_cpu_cpuid_test
+cglobal x264_cpu_cpuid
+cglobal x264_emms
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_cpu_cpuid_test( void ) return 0 if unsupported
+;-----------------------------------------------------------------------------
+x264_cpu_cpuid_test:
+ pushfd
+ push ebx
+ push ebp
+ push esi
+ push edi
+
+ pushfd
+ pop eax
+ mov ebx, eax
+ xor eax, 0x200000
+ push eax
+ popfd
+ pushfd
+ pop eax
+ xor eax, ebx
+
+ pop edi
+ pop esi
+ pop ebp
+ pop ebx
+ popfd
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
+;-----------------------------------------------------------------------------
+x264_cpu_cpuid:
+
+ push ebp
+ mov ebp, esp
+ push ebx
+ push esi
+ push edi
+
+ mov eax, [ebp + 8]
+ cpuid
+
+ mov esi, [ebp + 12]
+ mov [esi], eax
+
+ mov esi, [ebp + 16]
+ mov [esi], ebx
+
+ mov esi, [ebp + 20]
+ mov [esi], ecx
+
+ mov esi, [ebp + 24]
+ mov [esi], edx
+
+ pop edi
+ pop esi
+ pop ebx
+ pop ebp
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void __cdecl x264_emms( void )
+;-----------------------------------------------------------------------------
+x264_emms:
+ emms
+ ret
+
--- /dev/null
+/*****************************************************************************
+ * dct.c: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: dct-c.c,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "x264.h"
+
+#include "../dct.h"
+#include "dct.h"
+
+
+#if 0
+#define MMX_ZERO( MMZ ) \
+ asm volatile( "pxor " #MMZ ", " #MMZ "\n" :: )
+
+/* MMP : diff, MMT: temp */
+#define MMX_LOAD_DIFF_4P( MMP, MMT, MMZ, pix1, pix2 ) \
+ asm volatile( "movd (%0), " #MMP "\n" \
+ "punpcklbw " #MMZ ", " #MMP "\n" \
+ "movd (%1), " #MMT "\n" \
+ "punpcklbw " #MMZ ", " #MMT "\n" \
+ "psubw " #MMT ", " #MMP "\n" : : "r"(pix1), "r"(pix2) )
+
+/* in: out: mma=mma+mmb, mmb=mmb-mma */
+#define MMX_SUMSUB_BA( MMA, MMB ) \
+ asm volatile( "paddw " #MMB ", " #MMA "\n"\
+ "paddw " #MMB ", " #MMB "\n"\
+ "psubw " #MMA ", " #MMB "\n" :: )
+
+#define MMX_SUMSUB_BADC( MMA, MMB, MMC, MMD ) \
+ asm volatile( "paddw " #MMB ", " #MMA "\n"\
+ "paddw " #MMD ", " #MMC "\n"\
+ "paddw " #MMB ", " #MMB "\n"\
+ "paddw " #MMD ", " #MMD "\n"\
+ "psubw " #MMA ", " #MMB "\n"\
+ "psubw " #MMC ", " #MMD "\n" :: )
+
+/* inputs MMA, MMB output MMA MMT */
+#define MMX_SUMSUB2_AB( MMA, MMB, MMT ) \
+ asm volatile( "movq " #MMA ", " #MMT "\n" \
+ "paddw " #MMA ", " #MMA "\n" \
+ "paddw " #MMB ", " #MMA "\n" \
+ "psubw " #MMB ", " #MMT "\n" \
+ "psubw " #MMB ", " #MMT "\n" :: )
+
+/* inputs MMA, MMB output MMA MMS */
+#define MMX_SUMSUBD2_AB( MMA, MMB, MMT, MMS ) \
+ asm volatile( "movq " #MMA ", " #MMS "\n" \
+ "movq " #MMB ", " #MMT "\n" \
+ "psraw $1 , " #MMB "\n" \
+ "psraw $1 , " #MMS "\n" \
+ "paddw " #MMB ", " #MMA "\n" \
+ "psubw " #MMT ", " #MMS "\n" :: )
+
+#define SBUTTERFLYwd(a,b,t )\
+ asm volatile( "movq " #a ", " #t " \n\t" \
+ "punpcklwd " #b ", " #a " \n\t" \
+ "punpckhwd " #b ", " #t " \n\t" :: )
+
+#define SBUTTERFLYdq(a,b,t )\
+ asm volatile( "movq " #a ", " #t " \n\t" \
+ "punpckldq " #b ", " #a " \n\t" \
+ "punpckhdq " #b ", " #t " \n\t" :: )
+
+/* input ABCD output ADTC */
+#define MMX_TRANSPOSE( MMA, MMB, MMC, MMD, MMT ) \
+ SBUTTERFLYwd( MMA, MMB, MMT ); \
+ SBUTTERFLYwd( MMC, MMD, MMB ); \
+ SBUTTERFLYdq( MMA, MMC, MMD ); \
+ SBUTTERFLYdq( MMT, MMB, MMC )
+
+#define MMX_STORE_DIFF_4P( MMP, MMT, MM32, MMZ, dst ) \
+ asm volatile( "paddw " #MM32 "," #MMP "\n" \
+ "psraw $6, " #MMP "\n" \
+ "movd (%0), " #MMT "\n" \
+ "punpcklbw " #MMZ ", " #MMT "\n" \
+ "paddsw " #MMT ", " #MMP "\n" \
+ "packuswb " #MMZ ", " #MMP "\n" \
+ "movd " #MMP ", (%0)\n" :: "r"(dst) )
+
+#define UNUSED_LONGLONG( foo ) \
+ static const unsigned long long foo __asm__ (#foo) __attribute__((unused)) __attribute__((aligned(16)))
+
+UNUSED_LONGLONG( x264_mmx_32 ) = 0x0020002000200020ULL;
+UNUSED_LONGLONG( x264_mmx_1 ) = 0x0001000100010001ULL;
+
+
+/*
+ * XXX For all dct dc : input could be equal to output so ...
+ */
+void x264_dct4x4dc_mmxext( int16_t d[4][4] )
+{
+ /* load DCT */
+ asm volatile(
+ "movq (%0), %%mm0\n"
+ "movq 8(%0), %%mm1\n"
+ "movq 16(%0), %%mm2\n"
+ "movq 24(%0), %%mm3\n" :: "r"(d) );
+
+ MMX_SUMSUB_BADC( %%mm1, %%mm0, %%mm3, %%mm2 ); /* mm1=s01 mm0=d01 mm3=s23 mm2=d23 */
+ MMX_SUMSUB_BADC( %%mm3, %%mm1, %%mm2, %%mm0 ); /* mm3=s01+s23 mm1=s01-s23 mm2=d01+d23 mm0=d01-d23 */
+
+ /* in: mm3, mm1, mm0, mm2 out: mm3, mm2, mm4, mm0 */
+ MMX_TRANSPOSE ( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 );
+
+ MMX_SUMSUB_BADC( %%mm2, %%mm3, %%mm0, %%mm4 ); /* mm2=s01 mm3=d01 mm0=s23 mm4=d23 */
+ MMX_SUMSUB_BADC( %%mm0, %%mm2, %%mm4, %%mm3 ); /* mm0=s01+s23 mm2=s01-s23 mm4=d01+d23 mm3=d01-d23 */
+
+ /* in: mm0, mm2, mm3, mm4 out: mm0, mm4, mm1, mm3 */
+ MMX_TRANSPOSE ( %%mm0, %%mm2, %%mm3, %%mm4, %%mm1 );
+
+
+ asm volatile( "movq x264_mmx_1, %%mm6" :: );
+
+ /* Store back */
+ asm volatile(
+ "paddw %%mm6, %%mm0\n"
+ "paddw %%mm6, %%mm4\n"
+
+ "psraw $1, %%mm0\n"
+ "movq %%mm0, (%0)\n"
+ "psraw $1, %%mm4\n"
+ "movq %%mm4, 8(%0)\n"
+
+ "paddw %%mm6, %%mm1\n"
+ "paddw %%mm6, %%mm3\n"
+
+ "psraw $1, %%mm1\n"
+ "movq %%mm1, 16(%0)\n"
+ "psraw $1, %%mm3\n"
+ "movq %%mm3, 24(%0)\n" :: "r"(d) );
+}
+
+void x264_idct4x4dc_mmxext( int16_t d[4][4] )
+{
+ /* load DCT */
+ asm volatile(
+ "movq (%0), %%mm0\n"
+ "movq 8(%0), %%mm1\n"
+ "movq 16(%0), %%mm2\n"
+ "movq 24(%0), %%mm3\n" :: "r"(d) );
+
+ MMX_SUMSUB_BADC( %%mm1, %%mm0, %%mm3, %%mm2 ); /* mm1=s01 mm0=d01 mm3=s23 mm2=d23 */
+ MMX_SUMSUB_BADC( %%mm3, %%mm1, %%mm2, %%mm0 ); /* mm3=s01+s23 mm1=s01-s23 mm2=d01+d23 mm0=d01-d23 */
+
+ /* in: mm3, mm1, mm0, mm2 out: mm3, mm2, mm4, mm0 */
+ MMX_TRANSPOSE( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 );
+
+ MMX_SUMSUB_BADC( %%mm2, %%mm3, %%mm0, %%mm4 ); /* mm2=s01 mm3=d01 mm0=s23 mm4=d23 */
+ MMX_SUMSUB_BADC( %%mm0, %%mm2, %%mm4, %%mm3 ); /* mm0=s01+s23 mm2=s01-s23 mm4=d01+d23 mm3=d01-d23 */
+
+ /* in: mm0, mm2, mm3, mm4 out: mm0, mm4, mm1, mm3 */
+ MMX_TRANSPOSE( %%mm0, %%mm2, %%mm3, %%mm4, %%mm1 );
+
+ /* Store back */
+ asm volatile(
+ "movq %%mm0, (%0)\n"
+ "movq %%mm4, 8(%0)\n"
+ "movq %%mm1, 16(%0)\n"
+ "movq %%mm3, 24(%0)\n" :: "r"(d) );
+}
+
+/****************************************************************************
+ * subXxX_dct:
+ ****************************************************************************/
+inline void x264_sub4x4_dct_mmxext( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
+{
+ /* Reset mm7 */
+ MMX_ZERO( %%mm7 );
+
+ /* Load 4 lines */
+ MMX_LOAD_DIFF_4P( %%mm0, %%mm6, %%mm7, &pix1[0*i_pix1], &pix2[0*i_pix2] );
+ MMX_LOAD_DIFF_4P( %%mm1, %%mm6, %%mm7, &pix1[1*i_pix1], &pix2[1*i_pix2] );
+ MMX_LOAD_DIFF_4P( %%mm2, %%mm6, %%mm7, &pix1[2*i_pix1], &pix2[2*i_pix2] );
+ MMX_LOAD_DIFF_4P( %%mm3, %%mm6, %%mm7, &pix1[3*i_pix1], &pix2[3*i_pix2] );
+
+ MMX_SUMSUB_BADC( %%mm3, %%mm0, %%mm2, %%mm1 ); /* mm3=s03 mm0=d03 mm2=s12 mm1=d12 */
+
+ MMX_SUMSUB_BA( %%mm2, %%mm3 ); /* mm2=s03+s12 mm3=s03-s12 */
+ MMX_SUMSUB2_AB( %%mm0, %%mm1, %%mm4 ); /* mm0=2.d03+d12 mm4=d03-2.d12 */
+
+ /* transpose in: mm2, mm0, mm3, mm4, out: mm2, mm4, mm1, mm3 */
+ MMX_TRANSPOSE( %%mm2, %%mm0, %%mm3, %%mm4, %%mm1 );
+
+ MMX_SUMSUB_BADC( %%mm3, %%mm2, %%mm1, %%mm4 ); /* mm3=s03 mm2=d03 mm1=s12 mm4=d12 */
+
+ MMX_SUMSUB_BA( %%mm1, %%mm3 ); /* mm1=s03+s12 mm3=s03-s12 */
+ MMX_SUMSUB2_AB( %%mm2, %%mm4, %%mm0 ); /* mm2=2.d03+d12 mm0=d03-2.d12 */
+
+ /* transpose in: mm1, mm2, mm3, mm0, out: mm1, mm0, mm4, mm3 */
+ MMX_TRANSPOSE( %%mm1, %%mm2, %%mm3, %%mm0, %%mm4 );
+
+ /* Store back */
+ asm volatile(
+ "movq %%mm1, (%0)\n"
+ "movq %%mm0, 8(%0)\n"
+ "movq %%mm4, 16(%0)\n"
+ "movq %%mm3, 24(%0)\n" :: "r"(dct) );
+}
+#endif
+
+void x264_sub8x8_dct_mmxext( int16_t dct[4][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
+{
+ x264_sub4x4_dct_mmxext( dct[0], &pix1[0], i_pix1, &pix2[0], i_pix2 );
+ x264_sub4x4_dct_mmxext( dct[1], &pix1[4], i_pix1, &pix2[4], i_pix2 );
+ x264_sub4x4_dct_mmxext( dct[2], &pix1[4*i_pix1+0], i_pix1, &pix2[4*i_pix2+0], i_pix2 );
+ x264_sub4x4_dct_mmxext( dct[3], &pix1[4*i_pix1+4], i_pix1, &pix2[4*i_pix2+4], i_pix2 );
+}
+
+void x264_sub16x16_dct_mmxext( int16_t dct[16][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
+{
+ x264_sub8x8_dct_mmxext( &dct[ 0], &pix1[0], i_pix1, &pix2[0], i_pix2 );
+ x264_sub8x8_dct_mmxext( &dct[ 4], &pix1[8], i_pix1, &pix2[8], i_pix2 );
+ x264_sub8x8_dct_mmxext( &dct[ 8], &pix1[8*i_pix1], i_pix1, &pix2[8*i_pix2], i_pix2 );
+ x264_sub8x8_dct_mmxext( &dct[12], &pix1[8*i_pix1+8], i_pix1, &pix2[8*i_pix2+8], i_pix2 );
+}
+
+
+
+/****************************************************************************
+ * addXxX_idct:
+ ****************************************************************************/
+#if 0
+inline void x264_add4x4_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4] )
+{
+ /* Load dct coeffs */
+ asm volatile(
+ "movq (%0), %%mm0\n"
+ "movq 8(%0), %%mm1\n"
+ "movq 16(%0), %%mm2\n"
+ "movq 24(%0), %%mm3\n" :: "r"(dct) );
+
+ MMX_SUMSUB_BA ( %%mm2, %%mm0 ); /* mm2=s02 mm0=d02 */
+ MMX_SUMSUBD2_AB( %%mm1, %%mm3, %%mm5, %%mm4 ); /* mm1=s13 mm4=d13 ( well 1 + 3>>1 and 1>>1 + 3) */
+
+ MMX_SUMSUB_BADC( %%mm1, %%mm2, %%mm4, %%mm0 ); /* mm1=s02+s13 mm2=s02-s13 mm4=d02+d13 mm0=d02-d13 */
+
+ /* in: mm1, mm4, mm0, mm2 out: mm1, mm2, mm3, mm0 */
+ MMX_TRANSPOSE ( %%mm1, %%mm4, %%mm0, %%mm2, %%mm3 );
+
+ MMX_SUMSUB_BA ( %%mm3, %%mm1 ); /* mm3=s02 mm1=d02 */
+ MMX_SUMSUBD2_AB( %%mm2, %%mm0, %%mm5, %%mm4 ); /* mm2=s13 mm4=d13 ( well 1 + 3>>1 and 1>>1 + 3) */
+
+ MMX_SUMSUB_BADC( %%mm2, %%mm3, %%mm4, %%mm1 ); /* mm2=s02+s13 mm3=s02-s13 mm4=d02+d13 mm1=d02-d13 */
+
+ /* in: mm2, mm4, mm1, mm3 out: mm2, mm3, mm0, mm1 */
+ MMX_TRANSPOSE ( %%mm2, %%mm4, %%mm1, %%mm3, %%mm0 );
+
+ MMX_ZERO( %%mm7 );
+ asm volatile( "movq x264_mmx_32, %%mm6\n" :: );
+
+ MMX_STORE_DIFF_4P( %%mm2, %%mm4, %%mm6, %%mm7, &p_dst[0*i_dst] );
+ MMX_STORE_DIFF_4P( %%mm3, %%mm4, %%mm6, %%mm7, &p_dst[1*i_dst] );
+ MMX_STORE_DIFF_4P( %%mm0, %%mm4, %%mm6, %%mm7, &p_dst[2*i_dst] );
+ MMX_STORE_DIFF_4P( %%mm1, %%mm4, %%mm6, %%mm7, &p_dst[3*i_dst] );
+}
+#endif
+
+void x264_add8x8_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4][4] )
+{
+ x264_add4x4_idct_mmxext( p_dst, i_dst, dct[0] );
+ x264_add4x4_idct_mmxext( &p_dst[4], i_dst, dct[1] );
+ x264_add4x4_idct_mmxext( &p_dst[4*i_dst+0], i_dst, dct[2] );
+ x264_add4x4_idct_mmxext( &p_dst[4*i_dst+4], i_dst, dct[3] );
+}
+
+void x264_add16x16_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[16][4][4] )
+{
+ x264_add8x8_idct_mmxext( &p_dst[0], i_dst, &dct[0] );
+ x264_add8x8_idct_mmxext( &p_dst[8], i_dst, &dct[4] );
+ x264_add8x8_idct_mmxext( &p_dst[8*i_dst], i_dst, &dct[8] );
+ x264_add8x8_idct_mmxext( &p_dst[8*i_dst+8], i_dst, &dct[12] );
+}
--- /dev/null
+;*****************************************************************************
+;* dct.asm: h264 encoder library
+;*****************************************************************************
+;* Copyright (C) 2003 x264 project
+;* $Id: dct.asm,v 1.1 2004/06/03 19:27:07 fenrir Exp $
+;*
+;* Authors: Min Chen <chenm001.163.com> (converted to nasm)
+;* Laurent Aimar <fenrir@via.ecp.fr> (initial version)
+;*
+;* 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.
+;*****************************************************************************
+
+;*****************************************************************************
+;* *
+;* Revision history: *
+;* *
+;* 2004.04.28 portab all 4x4 function to nasm (CM) *
+;* *
+;*****************************************************************************
+
+BITS 32
+
+;=============================================================================
+; Macros and other preprocessor constants
+;=============================================================================
+
+%macro cglobal 1
+ %ifdef PREFIX
+ global _%1
+ %define %1 _%1
+ %else
+ global %1
+ %endif
+%endmacro
+
+%macro MMX_ZERO 1
+ pxor %1, %1
+%endmacro
+
+%macro MMX_LOAD_DIFF_4P 5
+ movd %1, %4
+ punpcklbw %1, %3
+ movd %2, %5
+ punpcklbw %2, %3
+ psubw %1, %2
+%endmacro
+
+%macro MMX_SUMSUB_BA 2
+ paddw %1, %2
+ paddw %2, %2
+ psubw %2, %1
+%endmacro
+
+%macro MMX_SUMSUB_BADC 4
+ paddw %1, %2
+ paddw %3, %4
+ paddw %2, %2
+ paddw %4, %4
+ psubw %2, %1
+ psubw %4, %3
+%endmacro
+
+%macro MMX_SUMSUB2_AB 3
+ movq %3, %1
+ paddw %1, %1
+ paddw %1, %2
+ psubw %3, %2
+ psubw %3, %2
+%endmacro
+
+%macro MMX_SUMSUBD2_AB 4
+ movq %4, %1
+ movq %3, %2
+ psraw %2, $1
+ psraw %4, $1
+ paddw %1, %2
+ psubw %4, %3
+%endmacro
+
+%macro SBUTTERFLYwd 3
+ movq %3, %1
+ punpcklwd %1, %2
+ punpckhwd %3, %2
+%endmacro
+
+%macro SBUTTERFLYdq 3
+ movq %3, %1
+ punpckldq %1, %2
+ punpckhdq %3, %2
+%endmacro
+
+;-----------------------------------------------------------------------------
+; input ABCD output ADTC
+;-----------------------------------------------------------------------------
+%macro MMX_TRANSPOSE 5
+ SBUTTERFLYwd %1, %2, %5
+ SBUTTERFLYwd %3, %4, %2
+ SBUTTERFLYdq %1, %3, %4
+ SBUTTERFLYdq %5, %2, %3
+%endmacro
+
+%macro MMX_STORE_DIFF_4P 5
+ paddw %1, %3
+ psraw %1, $6
+ movd %2, %5
+ punpcklbw %2, %4
+ paddsw %1, %2
+ packuswb %1, %1
+ movd %5, %1
+%endmacro
+
+;%macro
+;%endmacro
+
+;=============================================================================
+; Local Data (Read Only)
+;=============================================================================
+
+%ifdef FORMAT_COFF
+SECTION .rodata data
+%else
+SECTION .rodata data align=16
+%endif
+
+;-----------------------------------------------------------------------------
+; Various memory constants (trigonometric values or rounding values)
+;-----------------------------------------------------------------------------
+
+ALIGN 16
+x264_mmx_1:
+ dw 1, 1, 1, 1
+
+x264_mmx_32:
+ dw 32, 32, 32, 32
+
+;=============================================================================
+; Code
+;=============================================================================
+
+SECTION .text
+
+cglobal x264_dct4x4dc_mmxext
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void __cdecl dct4x4dc( int16_t d[4][4] )
+;-----------------------------------------------------------------------------
+x264_dct4x4dc_mmxext:
+ mov eax, [esp+ 4]
+ movq mm0, [eax+ 0]
+ movq mm1, [eax+ 8]
+ movq mm2, [eax+16]
+ movq mm3, [eax+24]
+
+ MMX_SUMSUB_BADC mm1, mm0, mm3, mm2 ; mm1=s01 mm0=d01 mm3=s23 mm2=d23
+ MMX_SUMSUB_BADC mm3, mm1, mm2, mm0 ; mm3=s01+s23 mm1=s01-s23 mm2=d01+d23 mm0=d01-d23
+
+ MMX_TRANSPOSE mm3, mm1, mm0, mm2, mm4 ; in: mm3, mm1, mm0, mm2 out: mm3, mm2, mm4, mm0
+
+ MMX_SUMSUB_BADC mm2, mm3, mm0, mm4 ; mm2=s01 mm3=d01 mm0=s23 mm4=d23
+ MMX_SUMSUB_BADC mm0, mm2, mm4, mm3 ; mm0=s01+s23 mm2=s01-s23 mm4=d01+d23 mm3=d01-d23
+
+ MMX_TRANSPOSE mm0, mm2, mm3, mm4, mm1 ; in: mm0, mm2, mm3, mm4 out: mm0, mm4, mm1, mm3
+
+ movq mm6, [x264_mmx_1]
+ paddw mm0, mm6
+ paddw mm4, mm6
+ psraw mm0, 1
+ movq [eax+ 0], mm0
+ psraw mm4, 1
+ movq [eax+ 8], mm4
+ paddw mm1, mm6
+ paddw mm3, mm6
+ psraw mm1, 1
+ movq [eax+16], mm1
+ psraw mm3, 1
+ movq [eax+24], mm3
+ ret
+
+cglobal x264_idct4x4dc_mmxext
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void __cdecl x264_idct4x4dc_mmxext( int16_t d[4][4] )
+;-----------------------------------------------------------------------------
+x264_idct4x4dc_mmxext:
+ mov eax, [esp+ 4]
+ movq mm0, [eax+ 0]
+ movq mm1, [eax+ 8]
+ movq mm2, [eax+16]
+ movq mm3, [eax+24]
+
+ MMX_SUMSUB_BADC mm1, mm0, mm3, mm2 ; mm1=s01 mm0=d01 mm3=s23 mm2=d23
+ MMX_SUMSUB_BADC mm3, mm1, mm2, mm0 ; mm3=s01+s23 mm1=s01-s23 mm2=d01+d23 mm0=d01-d23
+
+ MMX_TRANSPOSE mm3, mm1, mm0, mm2, mm4 ; in: mm3, mm1, mm0, mm2 out: mm3, mm2, mm4, mm0
+
+ MMX_SUMSUB_BADC mm2, mm3, mm0, mm4 ; mm2=s01 mm3=d01 mm0=s23 mm4=d23
+ MMX_SUMSUB_BADC mm0, mm2, mm4, mm3 ; mm0=s01+s23 mm2=s01-s23 mm4=d01+d23 mm3=d01-d23
+
+ MMX_TRANSPOSE mm0, mm2, mm3, mm4, mm1 ; in: mm0, mm2, mm3, mm4 out: mm0, mm4, mm1, mm3
+
+ movq [eax+ 0], mm0
+ movq [eax+ 8], mm4
+ movq [eax+16], mm1
+ movq [eax+24], mm3
+ ret
+
+cglobal x264_sub4x4_dct_mmxext
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void __cdecl x264_sub4x4_dct_mmxext( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
+;-----------------------------------------------------------------------------
+x264_sub4x4_dct_mmxext:
+ push ebx
+ mov eax, [esp+12] ; pix1
+ mov ebx, [esp+16] ; i_pix1
+ mov ecx, [esp+20] ; pix2
+ mov edx, [esp+24] ; i_pix2
+
+ MMX_ZERO mm7
+
+ ; Load 4 lines
+ MMX_LOAD_DIFF_4P mm0, mm6, mm7, [eax ], [ecx]
+ MMX_LOAD_DIFF_4P mm1, mm6, mm7, [eax+ebx ], [ecx+edx]
+ MMX_LOAD_DIFF_4P mm2, mm6, mm7, [eax+ebx*2], [ecx+edx*2]
+ add eax, ebx
+ add ecx, edx
+ MMX_LOAD_DIFF_4P mm3, mm6, mm7, [eax+ebx*2], [ecx+edx*2]
+
+ MMX_SUMSUB_BADC mm3, mm0, mm2, mm1 ; mm3=s03 mm0=d03 mm2=s12 mm1=d12
+
+ MMX_SUMSUB_BA mm2, mm3 ; mm2=s03+s12 mm3=s03-s12
+ MMX_SUMSUB2_AB mm0, mm1, mm4 ; mm0=2.d03+d12 mm4=d03-2.d12
+
+ ; transpose in: mm2, mm0, mm3, mm4, out: mm2, mm4, mm1, mm3
+ MMX_TRANSPOSE mm2, mm0, mm3, mm4, mm1
+
+ MMX_SUMSUB_BADC mm3, mm2, mm1, mm4 ; mm3=s03 mm2=d03 mm1=s12 mm4=d12
+
+ MMX_SUMSUB_BA mm1, mm3 ; mm1=s03+s12 mm3=s03-s12
+ MMX_SUMSUB2_AB mm2, mm4, mm0 ; mm2=2.d03+d12 mm0=d03-2.d12
+
+ ; transpose in: mm1, mm2, mm3, mm0, out: mm1, mm0, mm4, mm3
+ MMX_TRANSPOSE mm1, mm2, mm3, mm0, mm4
+
+ mov eax, [esp+ 8] ; dct
+ movq [eax+ 0], mm1
+ movq [eax+ 8], mm0
+ movq [eax+16], mm4
+ movq [eax+24], mm3
+
+ pop ebx
+ ret
+
+cglobal x264_add4x4_idct_mmxext
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void __cdecl x264_add4x4_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4] )
+;-----------------------------------------------------------------------------
+x264_add4x4_idct_mmxext:
+
+ ; Load dct coeffs
+ mov eax, [esp+12] ; dct
+ movq mm0, [eax+ 0]
+ movq mm4, [eax+ 8]
+ movq mm3, [eax+16]
+ movq mm1, [eax+24]
+
+ mov eax, [esp+ 4] ; p_dst
+ mov ecx, [esp+ 8] ; i_dst
+ lea edx, [ecx+ecx*2]
+
+ ; out:mm0, mm1, mm2, mm3
+ MMX_TRANSPOSE mm0, mm4, mm3, mm1, mm2
+
+ MMX_SUMSUB_BA mm2, mm0 ; mm2=s02 mm0=d02
+ MMX_SUMSUBD2_AB mm1, mm3, mm5, mm4 ; mm1=s13 mm4=d13 ( well 1 + 3>>1 and 1>>1 + 3)
+
+ MMX_SUMSUB_BADC mm1, mm2, mm4, mm0 ; mm1=s02+s13 mm2=s02-s13 mm4=d02+d13 mm0=d02-d13
+
+ ; in: mm1, mm4, mm0, mm2 out: mm1, mm2, mm3, mm0
+ MMX_TRANSPOSE mm1, mm4, mm0, mm2, mm3
+
+ MMX_SUMSUB_BA mm3, mm1 ; mm3=s02 mm1=d02
+ MMX_SUMSUBD2_AB mm2, mm0, mm5, mm4 ; mm2=s13 mm4=d13 ( well 1 + 3>>1 and 1>>1 + 3)
+
+ MMX_SUMSUB_BADC mm2, mm3, mm4, mm1 ; mm2=s02+s13 mm3=s02-s13 mm4=d02+d13 mm1=d02-d13
+
+ MMX_ZERO mm7
+ movq mm6, [x264_mmx_32]
+
+ MMX_STORE_DIFF_4P mm2, mm0, mm6, mm7, [eax]
+ MMX_STORE_DIFF_4P mm4, mm0, mm6, mm7, [eax+ecx]
+ MMX_STORE_DIFF_4P mm1, mm0, mm6, mm7, [eax+ecx*2]
+ MMX_STORE_DIFF_4P mm3, mm0, mm6, mm7, [eax+edx]
+
+ ret
+
--- /dev/null
+/*****************************************************************************
+ * dct.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: dct.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _I386_DCT_H
+#define _I386_DCT_H 1
+
+void x264_sub4x4_dct_mmxext( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
+void x264_sub8x8_dct_mmxext( int16_t dct[4][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
+void x264_sub16x16_dct_mmxext( int16_t dct[16][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
+
+void x264_add4x4_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4] );
+void x264_add8x8_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4][4] );
+void x264_add16x16_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[16][4][4] );
+
+void x264_dct4x4dc_mmxext( int16_t d[4][4] );
+void x264_idct4x4dc_mmxext( int16_t d[4][4] );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * mc.c: h264 encoder library (Motion Compensation)
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: mc-c.c,v 1.5 2004/06/18 01:59:58 chenm001 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.
+ *****************************************************************************/
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "x264.h" /* DECLARE_ALIGNED */
+#include "../mc.h"
+#include "../clip1.h"
+#include "mc.h"
+
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+#define USED_UINT64(foo) \
+ static const uint64_t foo __asm__ (#foo) __attribute__((used))
+#else
+#define USED_UINT64(foo) \
+ static const uint64_t foo __asm__ (#foo) __attribute__((unused))
+#endif
+
+USED_UINT64( x264_w0x10 ) = 0x0010001000100010ULL;
+
+
+#define MMX_ZERO( MMZ ) \
+ asm volatile( "pxor " #MMZ ", " #MMZ "\n" :: )
+
+#define MMX_INIT( MMV, NAME ) \
+ asm volatile( "movq " #NAME ", " #MMV "\n" :: )
+
+#define MMX_SAVE_4P( MMP, MMZ, dst ) \
+ asm volatile( "packuswb " #MMZ "," #MMP "\n" \
+ "movd " #MMP ", (%0)" :: "r"(dst) )
+
+#define MMX_LOAD_4P( MMP, MMZ, pix ) \
+ asm volatile( "movd (%0), " #MMP "\n" \
+ "punpcklbw " #MMZ ", " #MMP "\n" : : "r"(pix) )
+
+#define MMX_LOAD_4x4( MMP1, MMP2, MMP3, MMP4, MMZ, pix, i_pix )\
+ MMX_LOAD_4P( MMP1, MMZ, &(pix)[0*(i_pix)] ); \
+ MMX_LOAD_4P( MMP2, MMZ, &(pix)[1*(i_pix)] ); \
+ MMX_LOAD_4P( MMP3, MMZ, &(pix)[2*(i_pix)] ); \
+ MMX_LOAD_4P( MMP4, MMZ, &(pix)[3*(i_pix)] )
+
+#define MMX_LOAD_2x4( MMP1, MMP2, MMZ, pix, i_pix )\
+ MMX_LOAD_4P( MMP1, MMZ, &(pix)[0*(i_pix)] ); \
+ MMX_LOAD_4P( MMP2, MMZ, &(pix)[1*(i_pix)] )
+
+#define MMX_SAVEPACK_8P( MMP1, MMP2, MMZ, dst ) \
+ asm volatile( "packuswb " #MMP2 "," #MMP1 "\n" \
+ "movq " #MMP1 ", (%0)\n" :: "r"(dst) )
+
+
+#define MMX_LOAD_8P( MMP1, MMP2, MMZ, pix ) \
+ asm volatile( "movq (%0) , " #MMP1 "\n" \
+ "movq " #MMP1 ", " #MMP2 "\n" \
+ "punpcklbw " #MMZ ", " #MMP1 "\n" \
+ "punpckhbw " #MMZ ", " #MMP2 "\n" : : "r"(pix) )
+
+#define MMX_LOAD_2x8( MMP1, MMP2, MMP3, MMP4, MMZ, pix, i_pix )\
+ MMX_LOAD_8P( MMP1, MMP2, MMZ, &(pix)[0*(i_pix)] ); \
+ MMX_LOAD_8P( MMP3, MMP4, MMZ, &(pix)[1*(i_pix)] )
+
+#define SBUTTERFLYwd(a,b,t )\
+ asm volatile( "movq " #a ", " #t " \n\t" \
+ "punpcklwd " #b ", " #a " \n\t" \
+ "punpckhwd " #b ", " #t " \n\t" :: )
+
+#define SBUTTERFLYdq(a,b,t )\
+ asm volatile( "movq " #a ", " #t " \n\t" \
+ "punpckldq " #b ", " #a " \n\t" \
+ "punpckhdq " #b ", " #t " \n\t" :: )
+
+/* input ABCD output ADTC ( or 0?31-2->0123 ) */
+#define MMX_TRANSPOSE( MMA, MMB, MMC, MMD, MMT ) \
+ SBUTTERFLYwd( MMA, MMB, MMT ); \
+ SBUTTERFLYwd( MMC, MMD, MMB ); \
+ SBUTTERFLYdq( MMA, MMC, MMD ); \
+ SBUTTERFLYdq( MMT, MMB, MMC )
+
+/* first pass MM0 = MM0 -5*MM1 */
+#define MMX_FILTERTAP_P1( MMP0, MMP1 ) \
+ asm volatile( "psubw " #MMP1 "," #MMP0 "\n" \
+ "psllw $2, " #MMP1 "\n" \
+ "psubw " #MMP1 "," #MMP0 "\n" :: )
+ \
+/* second pass MM0 = MM0 + 20*(MM2+MM3) */
+#define MMX_FILTERTAP_P2( MMP0, MMP2, MMP3 ) \
+ asm volatile( "paddw " #MMP3 "," #MMP2 "\n" \
+ \
+ "psllw $2, " #MMP2 "\n" \
+ "paddw " #MMP2 "," #MMP0 "\n" \
+ "psllw $2, " #MMP2 "\n" \
+ "paddw " #MMP2 "," #MMP0 "\n" :: )
+
+/* last pass: MM0 = ( MM0 -5*MM1 + MM2 + MMV ) >> 5 */
+#define MMX_FILTERTAP_P3( MMP0, MMP1, MMP2, MMV, MMZ ) \
+ asm volatile( "psubw " #MMP1 "," #MMP0 "\n" \
+ "psllw $2, " #MMP1 "\n" \
+ "psubw " #MMP1 "," #MMP0 "\n" \
+ \
+ "paddw " #MMP2 "," #MMP0 "\n" \
+ "paddw " #MMV "," #MMP0 "\n" \
+ "psraw $5, " #MMP0 "\n" :: )
+
+#define MMX_FILTERTAP2_P1( MMP0, MMP1, MMP2, MMP3 ) \
+ asm volatile( "psubw " #MMP1 "," #MMP0 "\n" \
+ "psubw " #MMP3 "," #MMP2 "\n" \
+ "psllw $2, " #MMP1 "\n" \
+ "psllw $2, " #MMP3 "\n" \
+ "psubw " #MMP1 "," #MMP0 "\n" \
+ "psubw " #MMP3 "," #MMP2 "\n" :: )
+
+/* second pass MM0 = MM0 + 20*(MM1+MM2) */
+#define MMX_FILTERTAP2_P2( MMP0, MMP1, MMP2, MMP3, MMP4, MMP5 ) \
+ asm volatile( "paddw " #MMP2 "," #MMP1 "\n" \
+ "paddw " #MMP5 "," #MMP4 "\n" \
+ \
+ "psllw $2, " #MMP1 "\n" \
+ "psllw $2, " #MMP4 "\n" \
+ "paddw " #MMP1 "," #MMP0 "\n" \
+ "paddw " #MMP4 "," #MMP3 "\n" \
+ "psllw $2, " #MMP1 "\n" \
+ "psllw $2, " #MMP4 "\n" \
+ "paddw " #MMP1 "," #MMP0 "\n" \
+ "paddw " #MMP4 "," #MMP3 "\n" :: )
+
+#define MMX_LOAD_1r( m1, dst ) \
+ asm volatile( "movq (%0), " #m1 "\n" :: "r"(dst) ); \
+
+#define MMX_SAVE_1r( m1, dst ) \
+ asm volatile( "movq " #m1 ", (%0)\n" :: "r"(dst) ); \
+
+#define MMX_LOAD_2r( m1, m2, dst, i_dst ) \
+ asm volatile( "movq (%0), " #m1 "\n" :: "r"(&((uint8_t*)dst)[0*(i_dst)]) ); \
+ asm volatile( "movq (%0), " #m2 "\n" :: "r"(&((uint8_t*)dst)[1*(i_dst)]) )
+
+#define MMX_SAVE_2r( m1, m2, dst, i_dst ) \
+ asm volatile( "movq " #m1 ", (%0)\n" :: "r"(&((uint8_t*)dst)[0*(i_dst)]) ); \
+ asm volatile( "movq " #m2 ", (%0)\n" :: "r"(&((uint8_t*)dst)[1*(i_dst)]) )
+
+#define MMX_SAVE_4r( m1, m2, m3, m4, dst, i_dst ) \
+ asm volatile( "movq " #m1 ", (%0)\n" :: "r"(&((uint8_t*)dst)[0*(i_dst)]) ); \
+ asm volatile( "movq " #m2 ", (%0)\n" :: "r"(&((uint8_t*)dst)[1*(i_dst)]) ); \
+ asm volatile( "movq " #m3 ", (%0)\n" :: "r"(&((uint8_t*)dst)[2*(i_dst)]) ); \
+ asm volatile( "movq " #m4 ", (%0)\n" :: "r"(&((uint8_t*)dst)[3*(i_dst)]) )
+
+#define MMX_LOAD_4r( m1, m2, m3, m4, dst, i_dst ) \
+ asm volatile( "movq (%0), " #m1 "\n" :: "r"(&((uint8_t*)dst)[0*(i_dst)]) ); \
+ asm volatile( "movq (%0), " #m2 "\n" :: "r"(&((uint8_t*)dst)[1*(i_dst)]) ); \
+ asm volatile( "movq (%0), " #m3 "\n" :: "r"(&((uint8_t*)dst)[2*(i_dst)]) ); \
+ asm volatile( "movq (%0), " #m4 "\n" :: "r"(&((uint8_t*)dst)[3*(i_dst)]) )
+
+
+static inline int x264_tapfilter( uint8_t *pix, int i_pix_next )
+{
+ return pix[-2*i_pix_next] - 5*pix[-1*i_pix_next] + 20*(pix[0] + pix[1*i_pix_next]) - 5*pix[ 2*i_pix_next] + pix[ 3*i_pix_next];
+}
+static inline int x264_tapfilter1( uint8_t *pix )
+{
+ return pix[-2] - 5*pix[-1] + 20*(pix[0] + pix[1]) - 5*pix[ 2] + pix[ 3];
+}
+
+typedef void (*pf_mc_t)(uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height );
+
+/* NASM functions */
+extern void x264_pixel_avg_w4_mmxext( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
+extern void x264_pixel_avg_w8_mmxext( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
+extern void x264_pixel_avg_w16_mmxext( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
+extern void x264_pixel_avg_w16_sse2( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
+
+/* Macro to define NxM functions */
+/* mc I+H */
+#define MC_IH( name, cpu, width, height, off ) \
+static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
+{ \
+ DECLARE_ALIGNED( uint8_t, tmp[width*height], width ); \
+ \
+ mc_hh_w##width( src, i_src_stride, tmp, width, i_height ); \
+ x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
+ src+(off), i_src_stride, \
+ tmp, width, i_height ); \
+}
+
+/* mc I+V */
+#define MC_IV( name, cpu, width, height, off ) \
+static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
+{ \
+ DECLARE_ALIGNED( uint8_t, tmp[width*height], width ); \
+ \
+ mc_hv_w##width( src, i_src_stride, tmp, width, i_height ); \
+ x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
+ src+(off), i_src_stride, \
+ tmp, width, i_height ); \
+}
+
+/* mc H+V */
+#define MC_HV( name, cpu, width, height, off1, off2 ) \
+static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
+{ \
+ DECLARE_ALIGNED( uint8_t, tmp1[width*height], width ); \
+ DECLARE_ALIGNED( uint8_t, tmp2[width*height], width ); \
+ \
+ mc_hv_w##width( src+(off1), i_src_stride, tmp1, width, i_height ); \
+ mc_hh_w##width( src+(off2), i_src_stride, tmp2, width, i_height ); \
+ x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
+ tmp1, width, tmp2, width, \
+ i_height ); \
+}
+
+/* mc C+H */
+#define MC_CH( name, cpu, width, height, off ) \
+static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
+{ \
+ DECLARE_ALIGNED( uint8_t, tmp1[width*height], width ); \
+ DECLARE_ALIGNED( uint8_t, tmp2[width*height], width ); \
+ \
+ mc_hc_w##width( src, i_src_stride, tmp1, width, i_height ); \
+ mc_hh_w##width( src+(off), i_src_stride, tmp2, width, i_height ); \
+ x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
+ tmp1, width, tmp2, width, \
+ i_height ); \
+}
+
+/* mc C+V */
+#define MC_CV( name, cpu, width, height, off ) \
+static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
+{ \
+ DECLARE_ALIGNED( uint8_t, tmp1[width*height], width ); \
+ DECLARE_ALIGNED( uint8_t, tmp2[width*height], width ); \
+ \
+ mc_hc_w##width( src, i_src_stride, tmp1, width, i_height ); \
+ mc_hv_w##width( src+(off), i_src_stride, tmp2, width, i_height ); \
+ x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
+ tmp1, width, tmp2, width, \
+ i_height ); \
+}
+
+
+/*****************************************************************************
+ * MC with width == 4 (height <= 8)
+ *****************************************************************************/
+
+extern void x264_mc_copy_w4_mmxext( uint8_t *, int, uint8_t *, int, int );
+
+static inline void mc_hh_w4( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
+{
+ const int h4 = i_height / 4;
+ uint8_t srct[4*8*3];
+ uint64_t tmp[4];
+ int y;
+
+ src -= 2;
+
+ MMX_ZERO( %%mm7 );
+ MMX_INIT( %%mm6, x264_w0x10 );
+
+ for( y = 0; y < h4; y++ )
+ {
+ int i;
+
+ /* Preload data and transpose them */
+ MMX_LOAD_4x4 ( %%mm0, %%mm4, %%mm3, %%mm1, %%mm7, &src[0], i_src );
+ MMX_TRANSPOSE( %%mm0, %%mm4, %%mm3, %%mm1, %%mm2 ); /* 0123 */
+ MMX_SAVE_4r( %%mm0, %%mm1, %%mm2, %%mm3, &srct[4*8*0], 8 );
+
+ MMX_LOAD_4x4 ( %%mm0, %%mm4, %%mm3, %%mm1, %%mm7, &src[4], i_src );
+ MMX_TRANSPOSE( %%mm0, %%mm4, %%mm3, %%mm1, %%mm2 ); /* 0123 */
+ MMX_SAVE_4r( %%mm0, %%mm1, %%mm2, %%mm3, &srct[4*8*1], 8 );
+
+ /* we read 2 more bytes that needed */
+ MMX_LOAD_4x4 ( %%mm0, %%mm4, %%mm3, %%mm1, %%mm7, &src[8], i_src );
+ MMX_TRANSPOSE( %%mm0, %%mm4, %%mm3, %%mm1, %%mm2 ); /* 0123 */
+ MMX_SAVE_2r( %%mm0, %%mm1, &srct[4*8*2], 8 );
+
+ /* tap filter */
+ for( i = 0; i < 4; i++ )
+ {
+ MMX_LOAD_4r( %%mm0, %%mm1, %%mm2, %%mm3, &srct[8*(i+0)], 8 );
+ MMX_FILTERTAP_P1( %%mm0, %%mm1 );
+ MMX_FILTERTAP_P2( %%mm0, %%mm2, %%mm3 );
+
+ MMX_LOAD_2r( %%mm1, %%mm2, &srct[8*(i+4)], 8 );
+ MMX_FILTERTAP_P3( %%mm0, %%mm1, %%mm2, %%mm6, %%mm7 );
+
+ MMX_SAVE_1r( %%mm0, &tmp[i] );
+ }
+
+ MMX_LOAD_4r( %%mm0, %%mm4, %%mm3, %%mm1, tmp, 8 );
+ MMX_TRANSPOSE( %%mm0, %%mm4, %%mm3, %%mm1, %%mm2 ); /* 0123 */
+ MMX_SAVE_4P( %%mm0, %%mm7, &dst[0*i_dst] );
+ MMX_SAVE_4P( %%mm1, %%mm7, &dst[1*i_dst] );
+ MMX_SAVE_4P( %%mm2, %%mm7, &dst[2*i_dst] );
+ MMX_SAVE_4P( %%mm3, %%mm7, &dst[3*i_dst] );
+
+ src += 4 * i_src;
+ dst += 4 * i_dst;
+ }
+}
+static inline void mc_hv_w4( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
+{
+ int y;
+
+ src -= 2 * i_src;
+
+ MMX_ZERO( %%mm7 );
+ MMX_INIT( %%mm6, x264_w0x10 );
+
+ for( y = 0; y < i_height; y++ )
+ {
+ MMX_LOAD_4x4( %%mm0, %%mm1, %%mm2, %%mm3, %%mm7, src, i_src );
+ MMX_FILTERTAP_P1( %%mm0, %%mm1 );
+ MMX_FILTERTAP_P2( %%mm0, %%mm2, %%mm3 );
+
+ MMX_LOAD_2x4( %%mm4, %%mm5, %%mm7, &src[4*i_src], i_src );
+ MMX_FILTERTAP_P3( %%mm0, %%mm4, %%mm5, %%mm6, %%mm7 );
+ MMX_SAVE_4P( %%mm0, %%mm7, dst );
+
+ src += i_src;
+ dst += i_dst;
+ }
+}
+
+static inline void mc_hc_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ int i, x, y;
+
+ for( y = 0; y < i_height; y++ )
+ {
+ int16_t tap[5+4];
+
+ for( i = 0; i < 5+4; i++ )
+ {
+ tap[i] = x264_tapfilter( &src[-2+i], i_src_stride );
+ }
+
+ for( x = 0; x < 4; x++ )
+ {
+ dst[x] = x264_mc_clip1( ( tap[0+x] - 5*tap[1+x] + 20 * tap[2+x] + 20 * tap[3+x] -5*tap[4+x] + tap[5+x] + 512 ) >> 10 );
+ }
+
+ src += i_src_stride;
+ dst += i_dst_stride;
+ }
+}
+
+MC_IH( mc_xy10, mmxext, 4, 8, 0 )
+MC_IH( mc_xy30, mmxext, 4, 8, 1 )
+
+MC_IV( mc_xy01, mmxext, 4, 8, 0 )
+MC_IV( mc_xy03, mmxext, 4, 8, i_src_stride )
+
+MC_HV( mc_xy11, mmxext, 4, 8, 0, 0 )
+MC_HV( mc_xy31, mmxext, 4, 8, 1, 0 )
+MC_HV( mc_xy13, mmxext, 4, 8, 0, i_src_stride )
+MC_HV( mc_xy33, mmxext, 4, 8, 1, i_src_stride )
+
+MC_CH( mc_xy21, mmxext, 4, 8, 0 )
+MC_CH( mc_xy23, mmxext, 4, 8, i_src_stride )
+
+MC_CV( mc_xy12, mmxext, 4, 8, 0 )
+MC_CV( mc_xy32, mmxext, 4, 8, 1 )
+
+#if 0
+static void mc_xy10_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp[4*8];
+ mc_hh_w4( src, i_src_stride, tmp, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, src, i_src_stride, tmp, 4, i_height );
+}
+static void mc_xy30_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp[4*8];
+ mc_hh_w4( src, i_src_stride, tmp, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, src+1, i_src_stride, tmp, 4, i_height );
+}
+
+static void mc_xy01_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp[4*8];
+ mc_hv_w4( src, i_src_stride, tmp, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, src, i_src_stride, tmp, 4, i_height );
+}
+static void mc_xy03_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp[4*8];
+ mc_hv_w4( src, i_src_stride, tmp, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, src+i_src_stride, i_src_stride, tmp, 4, i_height );
+}
+
+static void mc_xy11_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[4*8];
+ uint8_t tmp2[4*8];
+
+ mc_hv_w4( src, i_src_stride, tmp1, 4, i_height );
+ mc_hh_w4( src, i_src_stride, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy31_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[4*8];
+ uint8_t tmp2[4*8];
+
+ mc_hv_w4( src+1, i_src_stride, tmp1, 4, i_height );
+ mc_hh_w4( src, i_src_stride, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy13_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[4*8];
+ uint8_t tmp2[4*8];
+
+ mc_hv_w4( src, i_src_stride, tmp1, 4, i_height );
+ mc_hh_w4( src+i_src_stride, i_src_stride, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy33_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[4*8];
+ uint8_t tmp2[4*8];
+
+ mc_hv_w4( src+1, i_src_stride, tmp1, 4, i_height );
+ mc_hh_w4( src+i_src_stride, i_src_stride, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
+}
+
+static void mc_xy21_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[4*8];
+ uint8_t tmp2[4*8];
+
+ mc_hc_w4( src, i_src_stride, tmp1, 4, i_height );
+ mc_hh_w4( src, i_src_stride, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy23_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[4*8];
+ uint8_t tmp2[4*8];
+
+ mc_hc_w4( src, i_src_stride, tmp1, 4, i_height );
+ mc_hh_w4( src+i_src_stride, i_src_stride, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
+}
+
+static void mc_xy12_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[4*8];
+ uint8_t tmp2[4*8];
+
+ mc_hc_w4( src, i_src_stride, tmp1, 4, i_height );
+ mc_hv_w4( src, i_src_stride, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy32_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[4*8];
+ uint8_t tmp2[4*8];
+
+ mc_hc_w4( src, i_src_stride, tmp1, 4, i_height );
+ mc_hv_w4( src+1, i_src_stride, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
+}
+#endif
+
+/*****************************************************************************
+ * MC with width == 8 (height <= 16)
+ *****************************************************************************/
+extern void x264_mc_copy_w8_mmxext( uint8_t *, int, uint8_t *, int, int );
+
+static inline void mc_hh_w8( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
+{
+ mc_hh_w4( &src[0], i_src, &dst[0], i_dst, i_height );
+ mc_hh_w4( &src[4], i_src, &dst[4], i_dst, i_height );
+}
+static inline void mc_hv_w8( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
+{
+ int y;
+
+ src -= 2 * i_src;
+
+ MMX_ZERO( %%mm7 );
+ MMX_INIT( %%mm6, x264_w0x10 );
+
+ for( y = 0; y < i_height; y++ )
+ {
+ MMX_LOAD_2x8( %%mm0, %%mm5, %%mm1, %%mm2, %%mm7, &src[0*i_src], i_src );
+ MMX_FILTERTAP2_P1( %%mm0, %%mm1, %%mm5, %%mm2 );
+
+
+ MMX_LOAD_2x8( %%mm1, %%mm3, %%mm2, %%mm4, %%mm7, &src[2*i_src], i_src );
+ MMX_FILTERTAP2_P2( %%mm0, %%mm1, %%mm2, %%mm5, %%mm3, %%mm4 );
+
+ MMX_LOAD_2x8( %%mm1, %%mm3, %%mm2, %%mm4, %%mm7, &src[4*i_src], i_src );
+ MMX_FILTERTAP_P3( %%mm0, %%mm1, %%mm2, %%mm6, %%mm7 );
+ MMX_FILTERTAP_P3( %%mm5, %%mm3, %%mm4, %%mm6, %%mm7 );
+
+ MMX_SAVEPACK_8P( %%mm0, %%mm5, %%mm7, dst );
+
+ src += i_src;
+ dst += i_dst;
+ }
+}
+
+static inline void mc_hc_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ int x, y;
+
+ asm volatile( "pxor %%mm7, %%mm7\n" : : );
+
+ for( y = 0; y < i_height; y++ )
+ {
+ int16_t tap[5+8];
+
+ /* first 8 */
+ asm volatile(
+ "leal (%0, %1), %%eax\n"
+
+ "movq (%0), %%mm0\n" /* load pix-2 */
+ "movq %%mm0, %%mm2\n"
+ "punpcklbw %%mm7, %%mm0\n"
+ "punpckhbw %%mm7, %%mm2\n"
+
+ "movq (%%eax),%%mm1\n" /* load pix-1 */
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7, %%mm1\n"
+ "punpckhbw %%mm7, %%mm3\n"
+ "psubw %%mm1, %%mm0\n"
+ "psllw $2, %%mm1\n"
+ "psubw %%mm1, %%mm0\n"
+ "psubw %%mm3, %%mm2\n"
+ "psllw $2, %%mm3\n"
+ "psubw %%mm3, %%mm2\n"
+
+ "movq (%%eax,%1),%%mm1\n" /* load pix */
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7, %%mm1\n"
+ "punpckhbw %%mm7, %%mm3\n"
+ "psllw $2, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+ "psllw $2, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+ "psllw $2, %%mm3\n"
+ "paddw %%mm3, %%mm2\n"
+ "psllw $2, %%mm3\n"
+ "paddw %%mm3, %%mm2\n"
+
+ "movq (%%eax,%1,2),%%mm1\n" /* load pix+1 */
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7, %%mm1\n"
+ "punpckhbw %%mm7, %%mm3\n"
+ "psllw $2, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+ "psllw $2, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+ "psllw $2, %%mm3\n"
+ "paddw %%mm3, %%mm2\n"
+ "psllw $2, %%mm3\n"
+ "paddw %%mm3, %%mm2\n"
+
+ "movq (%0,%1,4),%%mm1\n" /* load pix+2 */
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7, %%mm1\n"
+ "punpckhbw %%mm7, %%mm3\n"
+ "psubw %%mm1, %%mm0\n"
+ "psllw $2, %%mm1\n"
+ "psubw %%mm1, %%mm0\n"
+ "psubw %%mm3, %%mm2\n"
+ "psllw $2, %%mm3\n"
+ "psubw %%mm3, %%mm2\n"
+
+ "movq (%%eax,%1,4),%%mm1\n" /* load pix+3 */
+ "movq %%mm1, %%mm3\n"
+ "punpcklbw %%mm7, %%mm1\n"
+ "punpckhbw %%mm7, %%mm3\n"
+ "paddw %%mm1, %%mm0\n"
+ "paddw %%mm3, %%mm2\n"
+
+ "movq %%mm0, (%2)\n"
+ "movq %%mm2, 8(%2)\n"
+
+
+ "addl $8, %%eax\n"
+ "addl $8, %0\n"
+
+
+ "movd (%0), %%mm0\n" /* load pix-2 */
+ "punpcklbw %%mm7, %%mm0\n"
+
+ "movd (%%eax),%%mm1\n" /* load pix-1 */
+ "punpcklbw %%mm7, %%mm1\n"
+ "psubw %%mm1, %%mm0\n"
+ "psllw $2, %%mm1\n"
+ "psubw %%mm1, %%mm0\n"
+
+ "movd (%%eax,%1),%%mm1\n" /* load pix */
+ "punpcklbw %%mm7, %%mm1\n"
+ "psllw $2, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+ "psllw $2, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+
+ "movd (%%eax,%1,2),%%mm1\n" /* load pix+1 */
+ "punpcklbw %%mm7, %%mm1\n"
+ "psllw $2, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+ "psllw $2, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+
+ "movd (%0,%1,4),%%mm1\n" /* load pix+2 */
+ "punpcklbw %%mm7, %%mm1\n"
+ "psubw %%mm1, %%mm0\n"
+ "psllw $2, %%mm1\n"
+ "psubw %%mm1, %%mm0\n"
+
+ "movd (%%eax,%1,4),%%mm1\n" /* load pix+3 */
+ "punpcklbw %%mm7, %%mm1\n"
+ "paddw %%mm1, %%mm0\n"
+
+ "movq %%mm0, 16(%2)\n"
+ : : "r"(src-2*i_src_stride-2), "r"(i_src_stride), "r"(&tap[0]) : "%eax" );
+
+ /* last one */
+ tap[8+4] = x264_tapfilter( &src[-2+8+4], i_src_stride );
+
+ for( x = 0; x < 8; x++ )
+ {
+ dst[x] = x264_mc_clip1( ( tap[0+x] - 5*tap[1+x] + 20 * tap[2+x] + 20 * tap[3+x] -5*tap[4+x] + tap[5+x] + 512 ) >> 10 );
+ }
+
+ src += i_src_stride;
+ dst += i_dst_stride;
+ }
+}
+
+MC_IH( mc_xy10, mmxext, 8, 16, 0 )
+MC_IH( mc_xy30, mmxext, 8, 16, 1 )
+
+MC_IV( mc_xy01, mmxext, 8, 16, 0 )
+MC_IV( mc_xy03, mmxext, 8, 16, i_src_stride )
+
+MC_HV( mc_xy11, mmxext, 8, 16, 0, 0 )
+MC_HV( mc_xy31, mmxext, 8, 16, 1, 0 )
+MC_HV( mc_xy13, mmxext, 8, 16, 0, i_src_stride )
+MC_HV( mc_xy33, mmxext, 8, 16, 1, i_src_stride )
+
+MC_CH( mc_xy21, mmxext, 8, 16, 0 )
+MC_CH( mc_xy23, mmxext, 8, 16, i_src_stride )
+
+MC_CV( mc_xy12, mmxext, 8, 16, 0 )
+MC_CV( mc_xy32, mmxext, 8, 16, 1 )
+
+#if 0
+/* mc I+H */
+static void mc_xy10_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp[8*16];
+ mc_hh_w8( src, i_src_stride, tmp, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, src, i_src_stride, tmp, 8, i_height );
+}
+static void mc_xy30_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp[8*16];
+ mc_hh_w8( src, i_src_stride, tmp, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, src+1, i_src_stride, tmp, 8, i_height );
+}
+/* mc I+V */
+static void mc_xy01_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp[8*16];
+ mc_hv_w8( src, i_src_stride, tmp, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, src, i_src_stride, tmp, 8, i_height );
+}
+static void mc_xy03_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp[8*16];
+ mc_hv_w8( src, i_src_stride, tmp, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, src+i_src_stride, i_src_stride, tmp, 8, i_height );
+}
+/* H+V */
+static void mc_xy11_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[8*16];
+ uint8_t tmp2[8*16];
+
+ mc_hv_w8( src, i_src_stride, tmp1, 8, i_height );
+ mc_hh_w8( src, i_src_stride, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy31_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[8*16];
+ uint8_t tmp2[8*16];
+
+ mc_hv_w8( src+1, i_src_stride, tmp1, 8, i_height );
+ mc_hh_w8( src, i_src_stride, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy13_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[8*16];
+ uint8_t tmp2[8*16];
+
+ mc_hv_w8( src, i_src_stride, tmp1, 8, i_height );
+ mc_hh_w8( src+i_src_stride, i_src_stride, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy33_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[8*16];
+ uint8_t tmp2[8*16];
+
+ mc_hv_w8( src+1, i_src_stride, tmp1, 8, i_height );
+ mc_hh_w8( src+i_src_stride, i_src_stride, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy21_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[8*16];
+ uint8_t tmp2[8*16];
+
+ mc_hc_w8( src, i_src_stride, tmp1, 8, i_height );
+ mc_hh_w8( src, i_src_stride, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy12_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[8*16];
+ uint8_t tmp2[8*16];
+
+ mc_hc_w8( src, i_src_stride, tmp1, 8, i_height );
+ mc_hv_w8( src, i_src_stride, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy32_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[8*16];
+ uint8_t tmp2[8*16];
+
+ mc_hc_w8( src, i_src_stride, tmp1, 8, i_height );
+ mc_hv_w8( src+1, i_src_stride, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy23_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ uint8_t tmp1[8*16];
+ uint8_t tmp2[8*16];
+
+ mc_hc_w8( src, i_src_stride, tmp1, 8, i_height );
+ mc_hh_w8( src+i_src_stride, i_src_stride, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
+}
+#endif
+
+/*****************************************************************************
+ * MC with width == 16 (height <= 16)
+ *****************************************************************************/
+
+extern void x264_mc_copy_w16_mmxext( uint8_t *, int, uint8_t *, int, int );
+extern void x264_mc_copy_w16_sse2( uint8_t *, int, uint8_t *, int, int );
+
+static inline void mc_hh_w16( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
+{
+ mc_hh_w4( &src[ 0], i_src, &dst[ 0], i_dst, i_height );
+ mc_hh_w4( &src[ 4], i_src, &dst[ 4], i_dst, i_height );
+ mc_hh_w4( &src[ 8], i_src, &dst[ 8], i_dst, i_height );
+ mc_hh_w4( &src[12], i_src, &dst[12], i_dst, i_height );
+}
+static inline void mc_hv_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ mc_hv_w8( src, i_src_stride, dst, i_dst_stride, i_height );
+ mc_hv_w8( &src[8], i_src_stride, &dst[8], i_dst_stride, i_height );
+}
+
+static inline void mc_hc_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ mc_hc_w8( src, i_src_stride, dst, i_dst_stride, i_height );
+ mc_hc_w8( &src[8], i_src_stride, &dst[8], i_dst_stride, i_height );
+}
+
+/* MMX avg/copy */
+MC_IH( mc_xy10, mmxext, 16, 16, 0 )
+MC_IH( mc_xy30, mmxext, 16, 16, 1 )
+
+MC_IV( mc_xy01, mmxext, 16, 16, 0 )
+MC_IV( mc_xy03, mmxext, 16, 16, i_src_stride )
+
+MC_HV( mc_xy11, mmxext, 16, 16, 0, 0 )
+MC_HV( mc_xy31, mmxext, 16, 16, 1, 0 )
+MC_HV( mc_xy13, mmxext, 16, 16, 0, i_src_stride )
+MC_HV( mc_xy33, mmxext, 16, 16, 1, i_src_stride )
+
+MC_CH( mc_xy21, mmxext, 16, 16, 0 )
+MC_CH( mc_xy23, mmxext, 16, 16, i_src_stride )
+
+MC_CV( mc_xy12, mmxext, 16, 16, 0 )
+MC_CV( mc_xy32, mmxext, 16, 16, 1 )
+
+/* SSE2 avg/copy */
+MC_IH( mc_xy10, sse2, 16, 16, 0 )
+MC_IH( mc_xy30, sse2, 16, 16, 1 )
+
+MC_IV( mc_xy01, sse2, 16, 16, 0 )
+MC_IV( mc_xy03, sse2, 16, 16, i_src_stride )
+
+MC_HV( mc_xy11, sse2, 16, 16, 0, 0 )
+MC_HV( mc_xy31, sse2, 16, 16, 1, 0 )
+MC_HV( mc_xy13, sse2, 16, 16, 0, i_src_stride )
+MC_HV( mc_xy33, sse2, 16, 16, 1, i_src_stride )
+
+MC_CH( mc_xy21, sse2, 16, 16, 0 )
+MC_CH( mc_xy23, sse2, 16, 16, i_src_stride )
+
+MC_CV( mc_xy12, sse2, 16, 16, 0 )
+MC_CV( mc_xy32, sse2, 16, 16, 1 )
+
+
+#if 0
+/* mc I+H */
+static void mc_xy10_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp[16*16], 16);
+ mc_hh_w16( src, i_src_stride, tmp, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, src, i_src_stride, tmp, 16, i_height );
+}
+static void mc_xy30_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp[16*16], 16);
+ mc_hh_w16( src, i_src_stride, tmp, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, src+1, i_src_stride, tmp, 16, i_height );
+}
+/* mc I+V */
+static void mc_xy01_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp[16*16], 16);
+ mc_hv_w16( src, i_src_stride, tmp, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, src, i_src_stride, tmp, 16, i_height );
+}
+static void mc_xy03_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp[16*16], 16);
+ mc_hv_w16( src, i_src_stride, tmp, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, src+i_src_stride, i_src_stride, tmp, 16, i_height );
+}
+/* H+V */
+static void mc_xy11_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
+ DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
+
+ mc_hv_w16( src, i_src_stride, tmp1, 16, i_height );
+ mc_hh_w16( src, i_src_stride, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
+}
+static void mc_xy31_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
+ DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
+
+ mc_hv_w16( src+1, i_src_stride, tmp1, 16, i_height );
+ mc_hh_w16( src, i_src_stride, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
+}
+static void mc_xy13_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
+ DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
+
+ mc_hv_w16( src, i_src_stride, tmp1, 16, i_height );
+ mc_hh_w16( src+i_src_stride, i_src_stride, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
+}
+static void mc_xy33_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
+ DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
+
+ mc_hv_w16( src+1, i_src_stride, tmp1, 16, i_height );
+ mc_hh_w16( src+i_src_stride, i_src_stride, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
+}
+static void mc_xy21_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
+ DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
+
+ mc_hc_w16( src, i_src_stride, tmp1, 16, i_height );
+ mc_hh_w16( src, i_src_stride, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
+}
+static void mc_xy12_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
+ DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
+
+ mc_hc_w16( src, i_src_stride, tmp1, 16, i_height );
+ mc_hv_w16( src, i_src_stride, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
+}
+static void mc_xy32_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
+ DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
+
+ mc_hc_w16( src, i_src_stride, tmp1, 16, i_height );
+ mc_hv_w16( src+1, i_src_stride, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
+}
+static void mc_xy23_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+{
+ DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
+ DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
+
+ mc_hc_w16( src, i_src_stride, tmp1, 16, i_height );
+ mc_hh_w16( src+i_src_stride, i_src_stride, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
+}
+#endif
+
+#define MOTION_COMPENSATION_LUMA \
+ src += (mvy >> 2) * i_src_stride + (mvx >> 2); \
+ if( i_width == 4 ) \
+ { \
+ pf_mc[0][mvy&0x03][mvx&0x03]( src, i_src_stride, dst, i_dst_stride, i_height ); \
+ } \
+ else if( i_width == 8 ) \
+ { \
+ pf_mc[1][mvy&0x03][mvx&0x03]( src, i_src_stride, dst, i_dst_stride, i_height ); \
+ } \
+ else if( i_width == 16 ) \
+ { \
+ pf_mc[2][mvy&0x03][mvx&0x03]( src, i_src_stride, dst, i_dst_stride, i_height ); \
+ } \
+ else \
+ { \
+ fprintf( stderr, "Error: motion_compensation_luma called with invalid width" ); \
+ }
+
+static void motion_compensation_luma_mmxext( uint8_t *src, int i_src_stride,
+ uint8_t *dst, int i_dst_stride,
+ int mvx,int mvy,
+ int i_width, int i_height )
+{
+ static const pf_mc_t pf_mc[3][4][4] = /*XXX [dqy][dqx] */
+ {
+ {
+ { x264_mc_copy_w4_mmxext, mc_xy10_w4_mmxext, mc_hh_w4, mc_xy30_w4_mmxext },
+ { mc_xy01_w4_mmxext, mc_xy11_w4_mmxext, mc_xy21_w4_mmxext, mc_xy31_w4_mmxext },
+ { mc_hv_w4, mc_xy12_w4_mmxext, mc_hc_w4, mc_xy32_w4_mmxext },
+ { mc_xy03_w4_mmxext, mc_xy13_w4_mmxext, mc_xy23_w4_mmxext, mc_xy33_w4_mmxext },
+ },
+ {
+ { x264_mc_copy_w8_mmxext, mc_xy10_w8_mmxext, mc_hh_w8, mc_xy30_w8_mmxext },
+ { mc_xy01_w8_mmxext, mc_xy11_w8_mmxext, mc_xy21_w8_mmxext, mc_xy31_w8_mmxext },
+ { mc_hv_w8, mc_xy12_w8_mmxext, mc_hc_w8, mc_xy32_w8_mmxext },
+ { mc_xy03_w8_mmxext, mc_xy13_w8_mmxext, mc_xy23_w8_mmxext, mc_xy33_w8_mmxext },
+ },
+ {
+ { x264_mc_copy_w16_mmxext, mc_xy10_w16_mmxext, mc_hh_w16, mc_xy30_w16_mmxext },
+ { mc_xy01_w16_mmxext, mc_xy11_w16_mmxext, mc_xy21_w16_mmxext, mc_xy31_w16_mmxext },
+ { mc_hv_w16, mc_xy12_w16_mmxext, mc_hc_w16, mc_xy32_w16_mmxext },
+ { mc_xy03_w16_mmxext, mc_xy13_w16_mmxext, mc_xy23_w16_mmxext, mc_xy33_w16_mmxext },
+ }
+ };
+
+ MOTION_COMPENSATION_LUMA
+}
+
+static void motion_compensation_luma_sse2( uint8_t *src, int i_src_stride,
+ uint8_t *dst, int i_dst_stride,
+ int mvx,int mvy,
+ int i_width, int i_height )
+{
+ static const pf_mc_t pf_mc[3][4][4] = /*XXX [dqy][dqx] */
+ {
+ {
+ { x264_mc_copy_w4_mmxext, mc_xy10_w4_mmxext, mc_hh_w4, mc_xy30_w4_mmxext },
+ { mc_xy01_w4_mmxext, mc_xy11_w4_mmxext, mc_xy21_w4_mmxext, mc_xy31_w4_mmxext },
+ { mc_hv_w4, mc_xy12_w4_mmxext, mc_hc_w4, mc_xy32_w4_mmxext },
+ { mc_xy03_w4_mmxext, mc_xy13_w4_mmxext, mc_xy23_w4_mmxext, mc_xy33_w4_mmxext },
+ },
+ {
+ { x264_mc_copy_w8_mmxext, mc_xy10_w8_mmxext, mc_hh_w8, mc_xy30_w8_mmxext },
+ { mc_xy01_w8_mmxext, mc_xy11_w8_mmxext, mc_xy21_w8_mmxext, mc_xy31_w8_mmxext },
+ { mc_hv_w8, mc_xy12_w8_mmxext, mc_hc_w8, mc_xy32_w8_mmxext },
+ { mc_xy03_w8_mmxext, mc_xy13_w8_mmxext, mc_xy23_w8_mmxext, mc_xy33_w8_mmxext },
+ },
+ {
+ { x264_mc_copy_w16_sse2, mc_xy10_w16_sse2, mc_hh_w16, mc_xy30_w16_sse2 },
+ { mc_xy01_w16_sse2, mc_xy11_w16_sse2, mc_xy21_w16_sse2, mc_xy31_w16_sse2 },
+ { mc_hv_w16, mc_xy12_w16_sse2, mc_hc_w16, mc_xy32_w16_sse2 },
+ { mc_xy03_w16_sse2, mc_xy13_w16_sse2, mc_xy23_w16_sse2, mc_xy33_w16_sse2 },
+ }
+ };
+ MOTION_COMPENSATION_LUMA
+}
+
+void x264_mc_mmxext_init( x264_mc_function_t pf[2] )
+{
+ pf[MC_LUMA] = motion_compensation_luma_mmxext;
+}
+void x264_mc_sse2_init( x264_mc_function_t pf[2] )
+{
+ pf[MC_LUMA] = motion_compensation_luma_sse2;
+}
+
--- /dev/null
+;*****************************************************************************
+;* mc.asm: h264 encoder library
+;*****************************************************************************
+;* Copyright (C) 2003 x264 project
+;* $Id: mc.asm,v 1.3 2004/06/18 01:59:58 chenm001 Exp $
+;*
+;* Authors: Min Chen <chenm001.163.com> (converted to nasm)
+;* Laurent Aimar <fenrir@via.ecp.fr> (init algorithm)
+;*
+;* 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.
+;*****************************************************************************
+
+;*****************************************************************************
+;* *
+;* Revision history: *
+;* *
+;* 2004.05.17 portab mc_copy_w4/8/16 (CM) *
+;* *
+;*****************************************************************************
+
+BITS 32
+
+;=============================================================================
+; Macros and other preprocessor constants
+;=============================================================================
+
+%macro cglobal 1
+ %ifdef PREFIX
+ global _%1
+ %define %1 _%1
+ %else
+ global %1
+ %endif
+%endmacro
+
+;=============================================================================
+; Local Data (Read Only)
+;=============================================================================
+
+%ifdef FORMAT_COFF
+SECTION .rodata data
+%else
+SECTION .rodata data align=16
+%endif
+
+;-----------------------------------------------------------------------------
+; Various memory constants (trigonometric values or rounding values)
+;-----------------------------------------------------------------------------
+
+ALIGN 16
+
+;=============================================================================
+; Code
+;=============================================================================
+
+SECTION .text
+
+cglobal x264_pixel_avg_w4_mmxext
+cglobal x264_pixel_avg_w8_mmxext
+cglobal x264_pixel_avg_w16_mmxext
+cglobal x264_pixel_avg_w16_sse2
+
+cglobal x264_mc_copy_w4_mmxext
+cglobal x264_mc_copy_w8_mmxext
+cglobal x264_mc_copy_w16_mmxext
+cglobal x264_mc_copy_w16_sse2
+
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void x264_pixel_avg_w4_mmxext( uint8_t *dst, int i_dst_stride,
+; uint8_t *src1, int i_src1_stride,
+; uint8_t *src2, int i_src2_stride,
+; int i_height );
+;-----------------------------------------------------------------------------
+x264_pixel_avg_w4_mmxext:
+ push ebp
+ push ebx
+ push esi
+ push edi
+
+ mov edi, [esp+20] ; dst
+ mov ebx, [esp+28] ; src1
+ mov ecx, [esp+36] ; src2
+ mov esi, [esp+24] ; i_dst_stride
+ mov eax, [esp+32] ; i_src1_stride
+ mov edx, [esp+40] ; i_src2_stride
+ mov ebp, [esp+44] ; i_height
+ALIGN 4
+.height_loop
+ movd mm0, [ebx]
+ pavgb mm0, [ecx]
+ movd mm1, [ebx+eax]
+ pavgb mm1, [ecx+edx]
+ movd [edi], mm0
+ movd [edi+esi], mm1
+ dec ebp
+ dec ebp
+ lea ebx, [ebx+eax*2]
+ lea ecx, [ecx+edx*2]
+ lea edi, [edi+esi*2]
+ jne .height_loop
+
+ pop edi
+ pop esi
+ pop ebx
+ pop ebp
+ ret
+
+
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void x264_pixel_avg_w8_mmxext( uint8_t *dst, int i_dst_stride,
+; uint8_t *src1, int i_src1_stride,
+; uint8_t *src2, int i_src2_stride,
+; int i_height );
+;-----------------------------------------------------------------------------
+x264_pixel_avg_w8_mmxext:
+ push ebp
+ push ebx
+ push esi
+ push edi
+
+ mov edi, [esp+20] ; dst
+ mov ebx, [esp+28] ; src1
+ mov ecx, [esp+36] ; src2
+ mov esi, [esp+24] ; i_dst_stride
+ mov eax, [esp+32] ; i_src1_stride
+ mov edx, [esp+40] ; i_src2_stride
+ mov ebp, [esp+44] ; i_height
+ALIGN 4
+.height_loop
+ movq mm0, [ebx]
+ pavgb mm0, [ecx]
+ movq [edi], mm0
+ dec ebp
+ lea ebx, [ebx+eax]
+ lea ecx, [ecx+edx]
+ lea edi, [edi+esi]
+ jne .height_loop
+
+ pop edi
+ pop esi
+ pop ebx
+ pop ebp
+ ret
+
+
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void x264_pixel_avg_w16_mmxext( uint8_t *dst, int i_dst_stride,
+; uint8_t *src1, int i_src1_stride,
+; uint8_t *src2, int i_src2_stride,
+; int i_height );
+;-----------------------------------------------------------------------------
+x264_pixel_avg_w16_mmxext:
+ push ebp
+ push ebx
+ push esi
+ push edi
+
+ mov edi, [esp+20] ; dst
+ mov ebx, [esp+28] ; src1
+ mov ecx, [esp+36] ; src2
+ mov esi, [esp+24] ; i_dst_stride
+ mov eax, [esp+32] ; i_src1_stride
+ mov edx, [esp+40] ; i_src2_stride
+ mov ebp, [esp+44] ; i_height
+ALIGN 4
+.height_loop
+ movq mm0, [ebx ]
+ movq mm1, [ebx+8]
+ pavgb mm0, [ecx ]
+ pavgb mm1, [ecx+8]
+ movq [edi ], mm0
+ movq [edi+8], mm1
+ dec ebp
+ lea ebx, [ebx+eax]
+ lea ecx, [ecx+edx]
+ lea edi, [edi+esi]
+ jne .height_loop
+
+ pop edi
+ pop esi
+ pop ebx
+ pop ebp
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void x264_pixel_avg_w16_sse2( uint8_t *dst, int i_dst_stride,
+; uint8_t *src1, int i_src1_stride,
+; uint8_t *src2, int i_src2_stride,
+; int i_height );
+;-----------------------------------------------------------------------------
+x264_pixel_avg_w16_sse2:
+ push ebp
+ push ebx
+ push esi
+ push edi
+
+ mov edi, [esp+20] ; dst
+ mov ebx, [esp+28] ; src1
+ mov ecx, [esp+36] ; src2
+ mov esi, [esp+24] ; i_dst_stride
+ mov eax, [esp+32] ; i_src1_stride
+ mov edx, [esp+40] ; i_src2_stride
+ mov ebp, [esp+44] ; i_height
+ALIGN 4
+.height_loop
+ movdqu xmm0, [ebx]
+ pavgb xmm0, [ecx]
+ movdqu [edi], xmm0
+
+ dec ebp
+ lea ebx, [ebx+eax]
+ lea ecx, [ecx+edx]
+ lea edi, [edi+esi]
+ jne .height_loop
+
+ pop edi
+ pop esi
+ pop ebx
+ pop ebp
+ ret
+
+
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void x264_mc_copy_w4_mmxext( uint8_t *src, int i_src_stride,
+; uint8_t *dst, int i_dst_stride, int i_height )
+;-----------------------------------------------------------------------------
+x264_mc_copy_w4_mmxext:
+ push ebx
+ push esi
+ push edi
+
+ mov esi, [esp+16] ; src
+ mov edi, [esp+24] ; dst
+ mov ebx, [esp+20] ; i_src_stride
+ mov edx, [esp+28] ; i_dst_stride
+ mov ecx, [esp+32] ; i_height
+ALIGN 4
+.height_loop
+ mov eax, [esi]
+ mov [edi], eax
+ mov eax, [esi+ebx]
+ mov [edi+edx], eax
+ lea esi, [esi+ebx*2]
+ lea edi, [edi+edx*2]
+ dec ecx
+ dec ecx
+ jne .height_loop
+
+ pop edi
+ pop esi
+ pop ebx
+ ret
+
+cglobal mc_copy_w8
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void x264_mc_copy_w8_mmxext( uint8_t *src, int i_src_stride,
+; uint8_t *dst, int i_dst_stride, int i_height )
+;-----------------------------------------------------------------------------
+x264_mc_copy_w8_mmxext:
+ push ebx
+ push esi
+ push edi
+
+ mov esi, [esp+16] ; src
+ mov edi, [esp+24] ; dst
+ mov ebx, [esp+20] ; i_src_stride
+ mov edx, [esp+28] ; i_dst_stride
+ mov ecx, [esp+32] ; i_height
+ALIGN 4
+.height_loop
+ movq mm0, [esi]
+ movq [edi], mm0
+ movq mm1, [esi+ebx]
+ movq [edi+edx], mm1
+ movq mm2, [esi+ebx*2]
+ movq [edi+edx*2], mm2
+ lea esi, [esi+ebx*2]
+ lea edi, [edi+edx*2]
+ movq mm3, [esi+ebx]
+ movq [edi+edx], mm3
+ lea esi, [esi+ebx*2]
+ lea edi, [edi+edx*2]
+
+ sub ecx, byte 4
+ jnz .height_loop
+
+ pop edi
+ pop esi
+ pop ebx
+ ret
+
+cglobal mc_copy_w16
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void x264_mc_copy_w16_mmxext( uint8_t *src, int i_src_stride,
+; uint8_t *dst, int i_dst_stride, int i_height )
+;-----------------------------------------------------------------------------
+x264_mc_copy_w16_mmxext:
+ push ebx
+ push esi
+ push edi
+
+ mov esi, [esp+16] ; src
+ mov edi, [esp+24] ; dst
+ mov ebx, [esp+20] ; i_src_stride
+ mov edx, [esp+28] ; i_dst_stride
+ mov ecx, [esp+32] ; i_height
+
+ALIGN 4
+.height_loop
+ movq mm0, [esi]
+ movq mm1, [esi+8]
+ movq [edi], mm0
+ movq [edi+8], mm1
+ movq mm2, [esi+ebx]
+ movq mm3, [esi+ebx+8]
+ movq [edi+edx], mm2
+ movq [edi+edx+8], mm3
+ movq mm4, [esi+ebx*2]
+ movq mm5, [esi+ebx*2+8]
+ movq [edi+edx*2], mm4
+ movq [edi+edx*2+8], mm5
+ lea esi, [esi+ebx*2]
+ lea edi, [edi+edx*2]
+ movq mm6, [esi+ebx]
+ movq mm7, [esi+ebx+8]
+ movq [edi+edx], mm6
+ movq [edi+edx+8], mm7
+ lea esi, [esi+ebx*2]
+ lea edi, [edi+edx*2]
+ sub ecx, byte 4
+ jnz .height_loop
+
+ pop edi
+ pop esi
+ pop ebx
+ ret
+
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; void x264_mc_copy_w16_sse2( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
+;-----------------------------------------------------------------------------
+x264_mc_copy_w16_sse2:
+ push ebx
+ push esi
+ push edi
+
+ mov esi, [esp+16] ; src
+ mov edi, [esp+24] ; dst
+ mov ebx, [esp+20] ; i_src_stride
+ mov edx, [esp+28] ; i_dst_stride
+ mov ecx, [esp+32] ; i_height
+
+ALIGN 4
+.height_loop
+ movdqu xmm0, [esi]
+ movdqu xmm1, [esi+ebx]
+ movdqu [edi], xmm0
+ movdqu [edi+edx], xmm1
+ dec ecx
+ dec ecx
+ lea esi, [esi+ebx*2]
+ lea edi, [edi+edx*2]
+ jnz .height_loop
+
+ pop edi
+ pop esi
+ pop ebx
+ ret
--- /dev/null
+/*****************************************************************************
+ * mc.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: mc.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _I386_MC_H
+#define _I386_MC_H 1
+
+void x264_mc_mmxext_init( x264_mc_function_t pf[2] );
+void x264_mc_sse2_init( x264_mc_function_t pf[2] );
+
+#endif
--- /dev/null
+;*****************************************************************************
+;* pixel.asm: h264 encoder library
+;*****************************************************************************
+;* Copyright (C) 2003 x264 project
+;* $Id: pixel.asm,v 1.1 2004/06/03 19:27:07 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.
+;*****************************************************************************
+
+BITS 32
+
+;=============================================================================
+; Macros and other preprocessor constants
+;=============================================================================
+
+%macro cglobal 1
+ %ifdef PREFIX
+ global _%1
+ %define %1 _%1
+ %else
+ global %1
+ %endif
+%endmacro
+
+%macro SAD_INC_2x16P 0
+ movq mm1, [eax]
+ movq mm2, [ecx]
+ movq mm3, [eax+8]
+ movq mm4, [ecx+8]
+
+ psadbw mm1, mm2
+ psadbw mm3, mm4
+ paddw mm0, mm1
+ paddw mm0, mm3
+
+ movq mm1, [eax+ebx]
+ movq mm2, [ecx+edx]
+ movq mm3, [eax+ebx+8]
+ movq mm4, [ecx+edx+8]
+
+ psadbw mm1, mm2
+ psadbw mm3, mm4
+ paddw mm0, mm1
+ paddw mm0, mm3
+
+ lea eax, [eax+2*ebx]
+ lea ecx, [ecx+2*edx]
+%endmacro
+
+%macro SAD_INC_2x8P 0
+ movq mm1, [eax]
+ movq mm2, [ecx]
+ movq mm3, [eax+ebx]
+ movq mm4, [ecx+edx]
+
+ psadbw mm1, mm2
+ psadbw mm3, mm4
+ paddw mm0, mm1
+ paddw mm0, mm3
+
+ lea eax, [eax+2*ebx]
+ lea ecx, [ecx+2*edx]
+%endmacro
+
+%macro SAD_INC_2x4P 0
+ movd mm1, [eax]
+ movd mm2, [ecx]
+ movd mm3, [eax+ebx]
+ movd mm4, [ecx+edx]
+
+ psadbw mm1, mm2
+ psadbw mm3, mm4
+ paddw mm0, mm1
+ paddw mm0, mm3
+
+ lea eax, [eax+2*ebx]
+ lea ecx, [ecx+2*edx]
+%endmacro
+
+%macro LOAD_DIFF_4P 5 ; MMP, MMT, MMZ, [pix1], [pix2]
+ movd %1, %4
+ punpcklbw %1, %3
+ movd %2, %5
+ punpcklbw %2, %3
+ psubw %1, %2
+%endmacro
+
+%macro LOAD_DIFF_INC_4x4 11 ; p1,p2,p3,p4, t, z, pix1, i_pix1, pix2, i_pix2, offset
+ LOAD_DIFF_4P %1, %5, %6, [%7+%11], [%9+%11]
+ LOAD_DIFF_4P %2, %5, %6, [%7+%8+%11], [%9+%10+%11]
+ lea %7, [%7+2*%8]
+ lea %9, [%9+2*%10]
+ LOAD_DIFF_4P %3, %5, %6, [%7+%11], [%9+%11]
+ LOAD_DIFF_4P %4, %5, %6, [%7+%8+%11], [%9+%10+%11]
+ lea %7, [%7+2*%8]
+ lea %9, [%9+2*%10]
+%endmacro
+
+%macro HADAMARD4_SUB_BADC 4
+ paddw %1, %2
+ paddw %3, %4
+ paddw %2, %2
+ paddw %4, %4
+ psubw %2, %1
+ psubw %4, %3
+%endmacro
+
+%macro HADAMARD4x4 4
+ HADAMARD4_SUB_BADC %1, %2, %3, %4
+ HADAMARD4_SUB_BADC %1, %3, %2, %4
+%endmacro
+
+%macro SBUTTERFLYwd 3
+ movq %3, %1
+ punpcklwd %1, %2
+ punpckhwd %3, %2
+%endmacro
+
+%macro SBUTTERFLYdq 3
+ movq %3, %1
+ punpckldq %1, %2
+ punpckhdq %3, %2
+%endmacro
+
+%macro TRANSPOSE4x4 5 ; abcd-t -> adtc
+ SBUTTERFLYwd %1, %2, %5
+ SBUTTERFLYwd %3, %4, %2
+ SBUTTERFLYdq %1, %3, %4
+ SBUTTERFLYdq %5, %2, %3
+%endmacro
+
+%macro MMX_ABS 2 ; mma, mmt
+ pxor %2, %2
+ psubw %2, %1
+ pmaxsw %1, %2
+%endmacro
+
+%macro MMX_ABS_SUM 3 ; mma, mmt, mms
+ pxor %2, %2
+ psubw %2, %1
+ pmaxsw %1, %2
+ paddusw %3, %1
+%endmacro
+
+
+%macro MMX_SUM_MM 2 ; mmv, mmt
+ movq %2, %1
+ psrlq %1, 32
+ paddusw %1, %2
+ movq %2, %1
+ psrlq %1, 16
+ paddusw %1, %2
+ movd eax,%1
+ and eax,0xffff
+ shr eax,1
+%endmacro
+
+%macro HADAMARD4x4_FIRST 0
+ HADAMARD4x4 mm0, mm1, mm2, mm3
+ TRANSPOSE4x4 mm0, mm1, mm2, mm3, mm4
+ HADAMARD4x4 mm0, mm3, mm4, mm2
+ MMX_ABS mm0, mm7
+ MMX_ABS_SUM mm3, mm7, mm0
+ MMX_ABS_SUM mm4, mm7, mm0
+ MMX_ABS_SUM mm2, mm7, mm0
+%endmacro
+
+%macro HADAMARD4x4_NEXT 0
+ HADAMARD4x4 mm1, mm2, mm3, mm4
+ TRANSPOSE4x4 mm1, mm2, mm3, mm4, mm5
+ HADAMARD4x4 mm1, mm4, mm5, mm3
+ MMX_ABS_SUM mm1, mm7, mm0
+ MMX_ABS_SUM mm4, mm7, mm0
+ MMX_ABS_SUM mm5, mm7, mm0
+ MMX_ABS_SUM mm3, mm7, mm0
+%endmacro
+
+;=============================================================================
+; Code
+;=============================================================================
+
+SECTION .text
+
+cglobal x264_pixel_sad_16x16_mmxext
+cglobal x264_pixel_sad_16x8_mmxext
+cglobal x264_pixel_sad_8x16_mmxext
+cglobal x264_pixel_sad_8x8_mmxext
+cglobal x264_pixel_sad_8x4_mmxext
+cglobal x264_pixel_sad_4x8_mmxext
+cglobal x264_pixel_sad_4x4_mmxext
+
+cglobal x264_pixel_satd_4x4_mmxext
+cglobal x264_pixel_satd_4x8_mmxext
+cglobal x264_pixel_satd_8x4_mmxext
+cglobal x264_pixel_satd_8x8_mmxext
+cglobal x264_pixel_satd_16x8_mmxext
+cglobal x264_pixel_satd_8x16_mmxext
+cglobal x264_pixel_satd_16x16_mmxext
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_sad_16x16_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_sad_16x16_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm0, mm0
+
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+
+ movd eax, mm0
+
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_sad_16x8_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_sad_16x8_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm0, mm0
+
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+ SAD_INC_2x16P
+
+ movd eax, mm0
+
+ pop ebx
+ ret
+
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_sad_8x16_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_sad_8x16_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm0, mm0
+
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+
+ movd eax, mm0
+
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_sad_8x8_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_sad_8x8_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm0, mm0
+
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+
+ movd eax, mm0
+
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_sad_8x4_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_sad_8x4_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm0, mm0
+
+ SAD_INC_2x8P
+ SAD_INC_2x8P
+
+ movd eax, mm0
+
+ pop ebx
+ ret
+
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_sad_4x8_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_sad_4x8_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm0, mm0
+
+ SAD_INC_2x4P
+ SAD_INC_2x4P
+
+ SAD_INC_2x4P
+ SAD_INC_2x4P
+
+ movd eax, mm0
+
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_sad_4x4_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_sad_4x4_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm0, mm0
+
+ SAD_INC_2x4P
+ SAD_INC_2x4P
+
+ movd eax, mm0
+
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_satd_4x4_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_satd_4x4_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm7, mm7
+
+
+ LOAD_DIFF_4P mm0, mm6, mm7, [eax], [ecx]
+ LOAD_DIFF_4P mm1, mm6, mm7, [eax+ebx], [ecx+edx]
+ LOAD_DIFF_4P mm2, mm6, mm7, [eax+2*ebx], [ecx+2*edx]
+ add eax, ebx
+ add ecx, edx
+ LOAD_DIFF_4P mm3, mm6, mm7, [eax+2*ebx], [ecx+2*edx]
+
+ HADAMARD4x4_FIRST
+
+ MMX_SUM_MM mm0, mm7
+ pop ebx
+ ret
+
+
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_satd_4x8_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_satd_4x8_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm7, mm7
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_satd_8x4_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_satd_8x4_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm7, mm7
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_FIRST
+
+ mov eax, [esp+ 8] ; pix1
+ mov ecx, [esp+16] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_satd_8x8_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_satd_8x8_mmxext:
+ push ebx
+
+ mov eax, [esp+ 8] ; pix1
+ mov ebx, [esp+12] ; stride1
+ mov ecx, [esp+16] ; pix2
+ mov edx, [esp+20] ; stride2
+
+ pxor mm7, mm7
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ mov eax, [esp+ 8] ; pix1
+ mov ecx, [esp+16] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_satd_16x8_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_satd_16x8_mmxext:
+ push ebx
+ push ebp
+
+ mov eax, [esp+12] ; pix1
+ mov ebx, [esp+16] ; stride1
+ mov ecx, [esp+20] ; pix2
+ mov edx, [esp+24] ; stride2
+
+ pxor mm7, mm7
+ xor ebp, ebp
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ mov eax, [esp+12] ; pix1
+ mov ecx, [esp+20] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ mov ebp, eax
+
+ mov eax, [esp+12] ; pix1
+ mov ecx, [esp+20] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 8
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 8
+ HADAMARD4x4_NEXT
+
+ mov eax, [esp+12] ; pix1
+ mov ecx, [esp+20] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ add eax, ebp
+
+ pop ebp
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_satd_8x16_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_satd_8x16_mmxext:
+ push ebx
+ push ebp
+
+ mov eax, [esp+12] ; pix1
+ mov ebx, [esp+16] ; stride1
+ mov ecx, [esp+20] ; pix2
+ mov edx, [esp+24] ; stride2
+
+ pxor mm7, mm7
+ xor ebp, ebp
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ mov ebp, eax
+
+ mov eax, [esp+12] ; pix1
+ mov ecx, [esp+20] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ add eax, ebp
+
+ pop ebp
+ pop ebx
+ ret
+
+ALIGN 16
+;-----------------------------------------------------------------------------
+; int __cdecl x264_pixel_satd_16x16_mmxext (uint8_t *, int, uint8_t *, int )
+;-----------------------------------------------------------------------------
+x264_pixel_satd_16x16_mmxext:
+ push ebx
+ push ebp
+
+ mov eax, [esp+12] ; pix1
+ mov ebx, [esp+16] ; stride1
+ mov ecx, [esp+20] ; pix2
+ mov edx, [esp+24] ; stride2
+
+ pxor mm7, mm7
+ xor ebp, ebp
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ mov ebp, eax
+
+ mov eax, [esp+12] ; pix1
+ mov ecx, [esp+20] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ add ebp, eax
+
+ mov eax, [esp+12] ; pix1
+ mov ecx, [esp+20] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 8
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 8
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 8
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 8
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ add ebp, eax
+
+ mov eax, [esp+12] ; pix1
+ mov ecx, [esp+20] ; pix2
+
+ LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 12
+ HADAMARD4x4_FIRST
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
+ HADAMARD4x4_NEXT
+
+ LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
+ HADAMARD4x4_NEXT
+
+ MMX_SUM_MM mm0, mm7
+ add eax, ebp
+
+ pop ebp
+ pop ebx
+ ret
+
--- /dev/null
+/*****************************************************************************
+ * mc.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: pixel.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _I386_PIXEL_H
+#define _I386_PIXEL_H 1
+
+int x264_pixel_sad_16x16_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_sad_16x8_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_sad_8x16_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_sad_8x8_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_sad_8x4_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_sad_4x8_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_sad_4x4_mmxext( uint8_t *, int, uint8_t *, int );
+
+int x264_pixel_satd_16x16_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_satd_16x8_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_satd_8x16_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_satd_8x8_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_satd_8x4_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_satd_4x8_mmxext( uint8_t *, int, uint8_t *, int );
+int x264_pixel_satd_4x4_mmxext( uint8_t *, int, uint8_t *, int );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * predict.c: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: predict.c,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+/* XXX predict4x4 are inspired from ffmpeg h264 decoder
+ */
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "x264.h" /* for keyword inline */
+#include "../predict.h"
+#include "predict.h"
+
+static inline int clip_uint8( int a )
+{
+ if (a&(~255))
+ return (-a)>>31;
+ else
+ return a;
+}
+
+/****************************************************************************
+ * 16x16 prediction for intra block DC, H, V, P
+ ****************************************************************************/
+static void predict_16x16_dc( uint8_t *src, int i_stride )
+{
+ uint32_t dc = 0;
+ int i;
+
+ /* calculate DC value */
+ for( i = 0; i < 16; i++ )
+ {
+ dc += src[-1 + i * i_stride];
+ dc += src[i - i_stride];
+ }
+ dc = (( dc + 16 ) >> 5) * 0x01010101;
+
+ for( i = 0; i < 16; i++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+
+ *p++ = dc;
+ *p++ = dc;
+ *p++ = dc;
+ *p++ = dc;
+
+ src += i_stride;
+ }
+}
+static void predict_16x16_dc_left( uint8_t *src, int i_stride )
+{
+ uint32_t dc = 0;
+ int i;
+
+ for( i = 0; i < 16; i++ )
+ {
+ dc += src[-1 + i * i_stride];
+ }
+ dc = (( dc + 8 ) >> 4) * 0x01010101;
+
+ for( i = 0; i < 16; i++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+
+ *p++ = dc;
+ *p++ = dc;
+ *p++ = dc;
+ *p++ = dc;
+
+ src += i_stride;
+ }
+}
+static void predict_16x16_dc_top( uint8_t *src, int i_stride )
+{
+ uint32_t dc = 0;
+ int i;
+
+ for( i = 0; i < 16; i++ )
+ {
+ dc += src[i - i_stride];
+ }
+ dc = (( dc + 8 ) >> 4) * 0x01010101;
+
+ for( i = 0; i < 16; i++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+
+ *p++ = dc;
+ *p++ = dc;
+ *p++ = dc;
+ *p++ = dc;
+
+ src += i_stride;
+ }
+}
+static void predict_16x16_dc_128( uint8_t *src, int i_stride )
+{
+ int i;
+
+ for( i = 0; i < 16; i++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+
+ *p++ = 0x80808080;
+ *p++ = 0x80808080;
+ *p++ = 0x80808080;
+ *p++ = 0x80808080;
+
+ src += i_stride;
+ }
+}
+static void predict_16x16_h( uint8_t *src, int i_stride )
+{
+ int i;
+
+ for( i = 0; i < 16; i++ )
+ {
+ const uint32_t v = 0x01010101 * src[-1];
+ uint32_t *p = (uint32_t*)src;
+
+ *p++ = v;
+ *p++ = v;
+ *p++ = v;
+ *p++ = v;
+
+ src += i_stride;
+
+ }
+}
+static void predict_16x16_v( uint8_t *src, int i_stride )
+{
+ int i;
+
+ asm volatile(
+ "movq (%0), %%mm0\n"
+ "movq 8(%0), %%mm1\n" :: "r"(&src[-i_stride]) );
+
+ for( i = 0; i < 16; i++ )
+ {
+ asm volatile(
+ "movq %%mm0, (%0)\n"
+ "movq %%mm1, 8(%0)\n" :: "r"(src) );
+ src += i_stride;
+ }
+}
+
+/****************************************************************************
+ * 8x8 prediction for intra chroma block DC, H, V, P
+ ****************************************************************************/
+static void predict_8x8_dc_128( uint8_t *src, int i_stride )
+{
+ int y;
+
+ for( y = 0; y < 8; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+
+ *p++ = 0x80808080;
+ *p++ = 0x80808080;
+
+ src += i_stride;
+ }
+}
+static void predict_8x8_dc_left( uint8_t *src, int i_stride )
+{
+ int y;
+ uint32_t dc0 = 0, dc1 = 0;
+
+ for( y = 0; y < 4; y++ )
+ {
+ dc0 += src[y * i_stride - 1];
+ dc1 += src[(y+4) * i_stride - 1];
+ }
+ dc0 = (( dc0 + 2 ) >> 2)*0x01010101;
+ dc1 = (( dc1 + 2 ) >> 2)*0x01010101;
+
+ for( y = 0; y < 4; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p++ = dc0;
+ *p++ = dc0;
+
+ src += i_stride;
+ }
+ for( y = 0; y < 4; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p++ = dc1;
+ *p++ = dc1;
+
+ src += i_stride;
+ }
+
+}
+static void predict_8x8_dc_top( uint8_t *src, int i_stride )
+{
+ int y, x;
+ uint32_t dc0 = 0, dc1 = 0;
+
+ for( x = 0; x < 4; x++ )
+ {
+ dc0 += src[x - i_stride];
+ dc1 += src[x + 4 - i_stride];
+ }
+ dc0 = (( dc0 + 2 ) >> 2)*0x01010101;
+ dc1 = (( dc1 + 2 ) >> 2)*0x01010101;
+
+ for( y = 0; y < 8; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p++ = dc0;
+ *p++ = dc1;
+
+ src += i_stride;
+ }
+}
+static void predict_8x8_dc( uint8_t *src, int i_stride )
+{
+ int y;
+ int s0 = 0, s1 = 0, s2 = 0, s3 = 0;
+ uint32_t dc0, dc1, dc2, dc3;
+ int i;
+
+ /* First do :
+ s0 s1
+ s2
+ s3
+ */
+ for( i = 0; i < 4; i++ )
+ {
+ s0 += src[i - i_stride];
+ s1 += src[i + 4 - i_stride];
+ s2 += src[-1 + i * i_stride];
+ s3 += src[-1 + (i+4)*i_stride];
+ }
+ /* now calculate
+ dc0 dc1
+ dc2 dc3
+ */
+ dc0 = (( s0 + s2 + 4 ) >> 3)*0x01010101;
+ dc1 = (( s1 + 2 ) >> 2)*0x01010101;
+ dc2 = (( s3 + 2 ) >> 2)*0x01010101;
+ dc3 = (( s1 + s3 + 4 ) >> 3)*0x01010101;
+
+ for( y = 0; y < 4; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p++ = dc0;
+ *p++ = dc1;
+
+ src += i_stride;
+ }
+
+ for( y = 0; y < 4; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p++ = dc2;
+ *p++ = dc3;
+
+ src += i_stride;
+ }
+}
+
+static void predict_8x8_h( uint8_t *src, int i_stride )
+{
+ int i;
+
+ for( i = 0; i < 8; i++ )
+ {
+ uint32_t v = 0x01010101 * src[-1];
+ uint32_t *p = (uint32_t*)src;
+
+ *p++ = v;
+ *p++ = v;
+
+ src += i_stride;
+ }
+}
+static void predict_8x8_v( uint8_t *src, int i_stride )
+{
+ int i;
+
+ asm volatile( "movq (%0), %%mm0\n" :: "r"(&src[-i_stride]) );
+
+ for( i = 0; i < 8; i++ )
+ {
+ asm volatile( "movq %%mm0, (%0)\n" :: "r"(src) );
+ src += i_stride;
+ }
+}
+
+
+/****************************************************************************
+ * 4x4 prediction for intra luma block DC, H, V, P
+ ****************************************************************************/
+static void predict_4x4_dc_128( uint8_t *src, int i_stride )
+{
+ int y;
+ for( y = 0; y < 4; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p = 0x80808080;
+
+ src += i_stride;
+ }
+}
+static void predict_4x4_dc_left( uint8_t *src, int i_stride )
+{
+ int y;
+ uint32_t dc = (( src[-1+0*i_stride] + src[-1+i_stride]+
+ src[-1+2*i_stride] + src[-1+3*i_stride] + 2 ) >> 2)*0x01010101;
+
+ for( y = 0; y < 4; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p = dc;
+
+ src += i_stride;
+ }
+}
+static void predict_4x4_dc_top( uint8_t *src, int i_stride )
+{
+ int y;
+ uint32_t dc = (( src[0 - i_stride] + src[1 - i_stride] +
+ src[2 - i_stride] + src[3 - i_stride] + 2 ) >> 2)*0x01010101;
+
+ for( y = 0; y < 4; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p = dc;
+ src += i_stride;
+ }
+}
+static void predict_4x4_dc( uint8_t *src, int i_stride )
+{
+ int y;
+ uint32_t dc = (( src[-1+0*i_stride] + src[-1+i_stride]+
+ src[-1+2*i_stride] + src[-1+3*i_stride] +
+ src[0 - i_stride] + src[1 - i_stride] +
+ src[2 - i_stride] + src[3 - i_stride] + 4 ) >> 3)*0x01010101;
+
+ for( y = 0; y < 4; y++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p = dc;
+
+ src += i_stride;
+ }
+}
+static void predict_4x4_h( uint8_t *src, int i_stride )
+{
+ int i;
+
+ for( i = 0; i < 4; i++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+ *p = 0x01010101*src[-1];
+
+ src += i_stride;
+ }
+}
+static void predict_4x4_v( uint8_t *src, int i_stride )
+{
+ uint32_t top = *((uint32_t*)&src[-i_stride]);
+ int i;
+
+ for( i = 0; i < 4; i++ )
+ {
+ uint32_t *p = (uint32_t*)src;
+
+ *p = top;
+
+ src += i_stride;
+ }
+}
+
+/****************************************************************************
+ * Exported functions:
+ ****************************************************************************/
+void x264_predict_16x16_init_mmxext( x264_predict_t pf[7] )
+{
+ pf[I_PRED_16x16_V ] = predict_16x16_v;
+ pf[I_PRED_16x16_H ] = predict_16x16_h;
+ pf[I_PRED_16x16_DC] = predict_16x16_dc;
+ pf[I_PRED_16x16_DC_LEFT]= predict_16x16_dc_left;
+ pf[I_PRED_16x16_DC_TOP ]= predict_16x16_dc_top;
+ pf[I_PRED_16x16_DC_128 ]= predict_16x16_dc_128;
+}
+
+void x264_predict_8x8_init_mmxext( x264_predict_t pf[7] )
+{
+ pf[I_PRED_CHROMA_V ] = predict_8x8_v;
+ pf[I_PRED_CHROMA_H ] = predict_8x8_h;
+ pf[I_PRED_CHROMA_DC] = predict_8x8_dc;
+ pf[I_PRED_CHROMA_DC_LEFT]= predict_8x8_dc_left;
+ pf[I_PRED_CHROMA_DC_TOP ]= predict_8x8_dc_top;
+ pf[I_PRED_CHROMA_DC_128 ]= predict_8x8_dc_128;
+}
+
+void x264_predict_4x4_init_mmxext( x264_predict_t pf[12] )
+{
+ pf[I_PRED_4x4_V] = predict_4x4_v;
+ pf[I_PRED_4x4_H] = predict_4x4_h;
+ pf[I_PRED_4x4_DC] = predict_4x4_dc;
+ pf[I_PRED_4x4_DC_LEFT]= predict_4x4_dc_left;
+ pf[I_PRED_4x4_DC_TOP] = predict_4x4_dc_top;
+ pf[I_PRED_4x4_DC_128] = predict_4x4_dc_128;
+}
+
--- /dev/null
+/*****************************************************************************
+ * predict.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: predict.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _I386_PREDICT_H
+#define _I386_PREDICT_H 1
+
+void x264_predict_16x16_init_mmxext ( x264_predict_t pf[7] );
+void x264_predict_8x8_init_mmxext ( x264_predict_t pf[7] );
+void x264_predict_4x4_init_mmxext ( x264_predict_t pf[12] );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * macroblock.c: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: macroblock.c,v 1.1 2004/06/03 19:27:06 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 "common.h"
+#include "macroblock.h"
+
+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 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} }
+};
+
+#if 0
+static const int i_chroma_qp_table[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
+};
+#endif
+
+int x264_mb_predict_intra4x4_mode( x264_t *h, int idx )
+{
+ const int ma = h->mb.cache.intra4x4_pred_mode[x264_scan8[idx] - 1];
+ const int mb = h->mb.cache.intra4x4_pred_mode[x264_scan8[idx] - 8];
+ const int m = X264_MIN( ma, mb );
+
+ if( m < 0 )
+ return I_PRED_4x4_DC;
+
+ return m;
+}
+
+int x264_mb_predict_non_zero_code( x264_t *h, int idx )
+{
+ const int za = h->mb.cache.non_zero_count[x264_scan8[idx] - 1];
+ const int zb = h->mb.cache.non_zero_count[x264_scan8[idx] - 8];
+
+ int i_ret = za + zb;
+
+ if( i_ret < 0x80 )
+ {
+ i_ret = ( i_ret + 1 ) >> 1;
+ }
+ return i_ret & 0x7f;
+}
+
+/****************************************************************************
+ * Scan and Quant functions
+ ****************************************************************************/
+void x264_mb_dequant_2x2_dc( int16_t dct[2][2], int i_qscale )
+{
+ const int i_qbits = i_qscale/6 - 1;
+
+ if( i_qbits >= 0 )
+ {
+ const int i_dmf = dequant_mf[i_qscale%6][0][0] << i_qbits;
+
+ dct[0][0] = dct[0][0] * i_dmf;
+ dct[0][1] = dct[0][1] * i_dmf;
+ dct[1][0] = dct[1][0] * i_dmf;
+ dct[1][1] = dct[1][1] * i_dmf;
+ }
+ else
+ {
+ const int i_dmf = dequant_mf[i_qscale%6][0][0];
+
+ dct[0][0] = ( dct[0][0] * i_dmf ) >> 1;
+ dct[0][1] = ( dct[0][1] * i_dmf ) >> 1;
+ dct[1][0] = ( dct[1][0] * i_dmf ) >> 1;
+ dct[1][1] = ( dct[1][1] * i_dmf ) >> 1;
+ }
+}
+
+void x264_mb_dequant_4x4_dc( int16_t dct[4][4], int i_qscale )
+{
+ const int i_qbits = i_qscale/6 - 2;
+ int x,y;
+
+ if( i_qbits >= 0 )
+ {
+ const int i_dmf = dequant_mf[i_qscale%6][0][0] << i_qbits;
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ dct[y][x] = dct[y][x] * i_dmf;
+ }
+ }
+ }
+ else
+ {
+ const int i_dmf = dequant_mf[i_qscale%6][0][0];
+ const int f = 1 << ( 1 + i_qbits );
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ dct[y][x] = ( dct[y][x] * i_dmf + f ) >> (-i_qbits);
+ }
+ }
+ }
+}
+
+void x264_mb_dequant_4x4( int16_t dct[4][4], int i_qscale )
+{
+ const int i_mf = i_qscale%6;
+ const int i_qbits = i_qscale/6;
+ int y;
+
+ for( y = 0; y < 4; y++ )
+ {
+ dct[y][0] = ( dct[y][0] * dequant_mf[i_mf][y][0] ) << i_qbits;
+ dct[y][1] = ( dct[y][1] * dequant_mf[i_mf][y][1] ) << i_qbits;
+ dct[y][2] = ( dct[y][2] * dequant_mf[i_mf][y][2] ) << i_qbits;
+ dct[y][3] = ( dct[y][3] * dequant_mf[i_mf][y][3] ) << i_qbits;
+ }
+}
+
+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;
+}
+
+void x264_mb_predict_mv( x264_t *h, int i_list, int idx, int i_width, int mvp[2] )
+{
+ const int i8 = x264_scan8[idx];
+ const int i_ref= h->mb.cache.ref[i_list][i8];
+ int i_refa = h->mb.cache.ref[i_list][i8 - 1];
+ int16_t *mv_a = h->mb.cache.mv[i_list][i8 - 1];
+ int i_refb = h->mb.cache.ref[i_list][i8 - 8];
+ int16_t *mv_b = h->mb.cache.mv[i_list][i8 - 8];
+ int i_refc = h->mb.cache.ref[i_list][i8 - 8 + i_width ];
+ int16_t *mv_c = h->mb.cache.mv[i_list][i8 - 8 + i_width];
+
+ int i_count;
+
+ if( (idx&0x03) == 3 || ( i_width == 2 && (idx&0x3) == 2 )|| i_refc == -2 )
+ {
+ i_refc = h->mb.cache.ref[i_list][i8 - 8 - 1];
+ mv_c = h->mb.cache.mv[i_list][i8 - 8 - 1];
+ }
+
+ if( h->mb.i_partition == D_16x8 )
+ {
+ if( idx == 0 && i_refb == i_ref )
+ {
+ mvp[0] = mv_b[0];
+ mvp[1] = mv_b[1];
+ return;
+ }
+ else if( idx != 0 && i_refa == i_ref )
+ {
+ mvp[0] = mv_a[0];
+ mvp[1] = mv_a[1];
+ return;
+ }
+ }
+ else if( h->mb.i_partition == D_8x16 )
+ {
+ if( idx == 0 && i_refa == i_ref )
+ {
+ mvp[0] = mv_a[0];
+ mvp[1] = mv_a[1];
+ return;
+ }
+ else if( idx != 0 && i_refc == i_ref )
+ {
+ mvp[0] = mv_c[0];
+ mvp[1] = mv_c[1];
+ return;
+ }
+ }
+
+ i_count = 0;
+ if( i_refa == i_ref ) i_count++;
+ if( i_refb == i_ref ) i_count++;
+ if( i_refc == i_ref ) i_count++;
+
+ if( i_count > 1 )
+ {
+ mvp[0] = x264_median( mv_a[0], mv_b[0], mv_c[0] );
+ mvp[1] = x264_median( mv_a[1], mv_b[1], mv_c[1] );
+ }
+ else if( i_count == 1 )
+ {
+ if( i_refa == i_ref )
+ {
+ mvp[0] = mv_a[0];
+ mvp[1] = mv_a[1];
+ }
+ else if( i_refb == i_ref )
+ {
+ mvp[0] = mv_b[0];
+ mvp[1] = mv_b[1];
+ }
+ else
+ {
+ mvp[0] = mv_c[0];
+ mvp[1] = mv_c[1];
+ }
+ }
+ else if( i_refb == -2 && i_refc == -2 && i_refa != -2 )
+ {
+ mvp[0] = mv_a[0];
+ mvp[1] = mv_a[1];
+ }
+ else
+ {
+ mvp[0] = x264_median( mv_a[0], mv_b[0], mv_c[0] );
+ mvp[1] = x264_median( mv_a[1], mv_b[1], mv_c[1] );
+ }
+}
+
+void x264_mb_predict_mv_16x16( x264_t *h, int i_list, int i_ref, int mvp[2] )
+{
+ int i_refa = h->mb.cache.ref[i_list][X264_SCAN8_0 - 1];
+ int16_t *mv_a = h->mb.cache.mv[i_list][X264_SCAN8_0 - 1];
+ int i_refb = h->mb.cache.ref[i_list][X264_SCAN8_0 - 8];
+ int16_t *mv_b = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8];
+ int i_refc = h->mb.cache.ref[i_list][X264_SCAN8_0 - 8 + 4];
+ int16_t *mv_c = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8 + 4];
+
+ int i_count;
+
+ if( i_refc == -2 )
+ {
+ i_refc = h->mb.cache.ref[i_list][X264_SCAN8_0 - 8 - 1];
+ mv_c = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8 - 1];
+ }
+
+ i_count = 0;
+ if( i_refa == i_ref ) i_count++;
+ if( i_refb == i_ref ) i_count++;
+ if( i_refc == i_ref ) i_count++;
+
+ if( i_count > 1 )
+ {
+ mvp[0] = x264_median( mv_a[0], mv_b[0], mv_c[0] );
+ mvp[1] = x264_median( mv_a[1], mv_b[1], mv_c[1] );
+ }
+ else if( i_count == 1 )
+ {
+ if( i_refa == i_ref )
+ {
+ mvp[0] = mv_a[0];
+ mvp[1] = mv_a[1];
+ }
+ else if( i_refb == i_ref )
+ {
+ mvp[0] = mv_b[0];
+ mvp[1] = mv_b[1];
+ }
+ else
+ {
+ mvp[0] = mv_c[0];
+ mvp[1] = mv_c[1];
+ }
+ }
+ else if( i_refb == -2 && i_refc == -2 && i_refa != -2 )
+ {
+ mvp[0] = mv_a[0];
+ mvp[1] = mv_a[1];
+ }
+ else
+ {
+ mvp[0] = x264_median( mv_a[0], mv_b[0], mv_c[0] );
+ mvp[1] = x264_median( mv_a[1], mv_b[1], mv_c[1] );
+ }
+}
+
+
+void x264_mb_predict_mv_pskip( x264_t *h, int mv[2] )
+{
+ int i_refa = h->mb.cache.ref[0][X264_SCAN8_0 - 1];
+ int i_refb = h->mb.cache.ref[0][X264_SCAN8_0 - 8];
+ int16_t *mv_a = h->mb.cache.mv[0][X264_SCAN8_0 - 1];
+ int16_t *mv_b = h->mb.cache.mv[0][X264_SCAN8_0 - 8];
+
+ if( i_refa == -2 || i_refb == -2 ||
+ ( i_refa == 0 && mv_a[0] == 0 && mv_a[1] == 0 ) ||
+ ( i_refb == 0 && mv_b[0] == 0 && mv_b[1] == 0 ) )
+ {
+ mv[0] = mv[1] = 0;
+ }
+ else
+ {
+ x264_mb_predict_mv_16x16( h, 0, 0, mv );
+ }
+}
+
+void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int mvc[4][2], int *i_mvc )
+{
+ int16_t (*mvr)[2] = h->mb.mvr[i_list][i_ref];
+
+ int i = 0;
+ if( h->mb.i_mb_x > 0 )
+ {
+ int i_mb_l = h->mb.i_mb_xy - 1;
+ mvc[i][0] = mvr[i_mb_l][0];
+ mvc[i][1] = mvr[i_mb_l][1];
+ i++;
+ }
+ if( h->mb.i_mb_y > 0 )
+ {
+ int i_mb_t = h->mb.i_mb_xy - h->mb.i_mb_stride;
+ mvc[i][0] = mvr[i_mb_t][0];
+ mvc[i][1] = mvr[i_mb_t][1];
+ i++;
+
+ if( h->mb.i_mb_x > 0 )
+ {
+ mvc[i][0] = mvr[i_mb_t - 1][0];
+ mvc[i][1] = mvr[i_mb_t - 1][1];
+ i++;
+ }
+ if( h->mb.i_mb_x < h->mb.i_mb_stride - 1 )
+ {
+ mvc[i][0] = mvr[i_mb_t + 1][0];
+ mvc[i][1] = mvr[i_mb_t + 1][1];
+ i++;
+ }
+ }
+ *i_mvc = i;
+}
+
+static inline void x264_mb_mc_0xywh( x264_t *h, int x, int y, int width, int height )
+{
+ const int i8 = x264_scan8[0]+x+8*y;
+ const int i_ref = h->mb.cache.ref[0][i8];
+ const int mvx = h->mb.cache.mv[0][i8][0];
+ const int mvy = h->mb.cache.mv[0][i8][1];
+
+ h->mc[MC_LUMA]( &h->mb.pic.p_fref[0][i_ref][0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
+ &h->mb.pic.p_fdec[0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
+ mvx, mvy, 4*width, 4*height );
+
+ h->mc[MC_CHROMA]( &h->mb.pic.p_fref[0][i_ref][1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
+ &h->mb.pic.p_fdec[1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
+ mvx, mvy, 2*width, 2*height );
+
+ h->mc[MC_CHROMA]( &h->mb.pic.p_fref[0][i_ref][2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
+ &h->mb.pic.p_fdec[2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
+ mvx, mvy, 2*width, 2*height );
+}
+static inline void x264_mb_mc_1xywh( x264_t *h, int x, int y, int width, int height )
+{
+ const int i8 = x264_scan8[0]+x+8*y;
+ const int i_ref = h->mb.cache.ref[1][i8];
+ const int mvx = h->mb.cache.mv[1][i8][0];
+ const int mvy = h->mb.cache.mv[1][i8][1];
+
+ h->mc[MC_LUMA]( &h->mb.pic.p_fref[1][i_ref][0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
+ &h->mb.pic.p_fdec[0][4*y *h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
+ mvx, mvy, 4*width, 4*height );
+
+ h->mc[MC_CHROMA]( &h->mb.pic.p_fref[1][i_ref][1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
+ &h->mb.pic.p_fdec[1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
+ mvx, mvy, 2*width, 2*height );
+
+ h->mc[MC_CHROMA]( &h->mb.pic.p_fref[1][i_ref][2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
+ &h->mb.pic.p_fdec[2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
+ mvx, mvy, 2*width, 2*height );
+}
+
+static inline void x264_mb_mc_01xywh( x264_t *h, int x, int y, int width, int height )
+{
+ const int i8 = x264_scan8[0]+x+8*y;
+
+ const int i_ref0 = h->mb.cache.ref[0][i8];
+ const int mvx0 = h->mb.cache.mv[0][i8][0];
+ const int mvy0 = h->mb.cache.mv[0][i8][1];
+
+ const int i_ref1 = h->mb.cache.ref[1][i8];
+ const int mvx1 = h->mb.cache.mv[1][i8][0];
+ const int mvy1 = h->mb.cache.mv[1][i8][1];
+ DECLARE_ALIGNED( uint8_t, tmp[16*16], 16 );
+ int i_mode = 0;
+
+ if( width == 4 && height == 4 ) i_mode = PIXEL_16x16;
+ else if( width == 4 && height == 2 ) i_mode = PIXEL_16x8;
+ else if( width == 2 && height == 4 ) i_mode = PIXEL_8x16;
+ else if( width == 2 && height == 2 ) i_mode = PIXEL_8x8;
+ else if( width == 2 && height == 1 ) i_mode = PIXEL_8x4;
+ else if( width == 1 && height == 2 ) i_mode = PIXEL_4x8;
+ else if( width == 1 && height == 1 ) i_mode = PIXEL_4x4;
+
+ h->mc[MC_LUMA]( &h->mb.pic.p_fref[0][i_ref0][0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
+ &h->mb.pic.p_fdec[0][4*y *h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
+ mvx0, mvy0, 4*width, 4*height );
+ h->mc[MC_CHROMA]( &h->mb.pic.p_fref[0][i_ref0][1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
+ &h->mb.pic.p_fdec[1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
+ mvx0, mvy0, 2*width, 2*height );
+ h->mc[MC_CHROMA]( &h->mb.pic.p_fref[0][i_ref0][2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
+ &h->mb.pic.p_fdec[2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
+ mvx0, mvy0, 2*width, 2*height );
+
+
+ h->mc[MC_LUMA]( &h->mb.pic.p_fref[1][i_ref1][0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
+ tmp, 16, mvx1, mvy1, 4*width, 4*height );
+ h->pixf.avg[i_mode]( &h->mb.pic.p_fdec[0][4*y *h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0], tmp, 16 );
+
+ h->mc[MC_CHROMA]( &h->mb.pic.p_fref[1][i_ref1][1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
+ tmp, 16, mvx1, mvy1, 2*width, 2*height );
+ h->pixf.avg[i_mode]( &h->mb.pic.p_fdec[1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1], tmp, 16 );
+
+ h->mc[MC_CHROMA]( &h->mb.pic.p_fref[1][i_ref1][2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
+ tmp, 16, mvx1, mvy1, 2*width, 2*height );
+ h->pixf.avg[i_mode]( &h->mb.pic.p_fdec[2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2], tmp, 16 );
+}
+
+
+void x264_mb_mc( x264_t *h )
+{
+ if( h->mb.i_type == P_L0 )
+ {
+ if( h->mb.i_partition == D_16x16 )
+ {
+ x264_mb_mc_0xywh( h, 0, 0, 4, 4 );
+ }
+ else if( h->mb.i_partition == D_16x8 )
+ {
+ x264_mb_mc_0xywh( h, 0, 0, 4, 2 );
+ x264_mb_mc_0xywh( h, 0, 2, 4, 2 );
+ }
+ else if( h->mb.i_partition == D_8x16 )
+ {
+ x264_mb_mc_0xywh( h, 0, 0, 2, 4 );
+ x264_mb_mc_0xywh( h, 2, 0, 2, 4 );
+ }
+ }
+ else if( h->mb.i_type == P_8x8 )
+ {
+ int i;
+ for( i = 0; i < 4; i++ )
+ {
+ const int x = 2*(i%2);
+ const int y = 2*(i/2);
+ switch( h->mb.i_sub_partition[i] )
+ {
+ case D_L0_8x8:
+ x264_mb_mc_0xywh( h, x, y, 2, 2 );
+ break;
+ case D_L0_8x4:
+ x264_mb_mc_0xywh( h, x, y+0, 2, 1 );
+ x264_mb_mc_0xywh( h, x, y+1, 2, 1 );
+ break;
+ case D_L0_4x8:
+ x264_mb_mc_0xywh( h, x+0, y, 1, 2 );
+ x264_mb_mc_0xywh( h, x+1, y, 1, 2 );
+ break;
+ case D_L0_4x4:
+ x264_mb_mc_0xywh( h, x+0, y+0, 1, 1 );
+ x264_mb_mc_0xywh( h, x+1, y+0, 1, 1 );
+ x264_mb_mc_0xywh( h, x+0, y+1, 1, 1 );
+ x264_mb_mc_0xywh( h, x+1, y+1, 1, 1 );
+ break;
+ }
+ }
+ }
+ else if( h->mb.i_type == B_8x8 || h->mb.i_type == B_DIRECT )
+ {
+ x264_log( h, X264_LOG_ERROR, "mc_luma with unsupported mb\n" );
+ return;
+ }
+ else /* B_*x* */
+ {
+ int b_list0[2];
+ int b_list1[2];
+
+ int i;
+
+ /* init ref list utilisations */
+ for( i = 0; i < 2; i++ )
+ {
+ b_list0[i] = x264_mb_type_list0_table[h->mb.i_type][i];
+ b_list1[i] = x264_mb_type_list1_table[h->mb.i_type][i];
+ }
+ if( h->mb.i_partition == D_16x16 )
+ {
+ if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 4, 4 );
+ else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 4, 4 );
+ else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 4, 4 );
+ }
+ else if( h->mb.i_partition == D_16x8 )
+ {
+ if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 4, 2 );
+ else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 4, 2 );
+ else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 4, 2 );
+
+ if( b_list0[1] && b_list1[1] ) x264_mb_mc_01xywh( h, 0, 2, 4, 2 );
+ else if( b_list0[1] ) x264_mb_mc_0xywh ( h, 0, 2, 4, 2 );
+ else if( b_list1[1] ) x264_mb_mc_1xywh ( h, 0, 2, 4, 2 );
+ }
+ else if( h->mb.i_partition == D_8x16 )
+ {
+ if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 2, 4 );
+ else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 2, 4 );
+ else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 2, 4 );
+
+ if( b_list0[1] && b_list1[1] ) x264_mb_mc_01xywh( h, 2, 0, 2, 4 );
+ else if( b_list0[1] ) x264_mb_mc_0xywh ( h, 2, 0, 2, 4 );
+ else if( b_list1[1] ) x264_mb_mc_1xywh ( h, 2, 0, 2, 4 );
+ }
+ }
+}
+
+void x264_macroblock_cache_init( x264_t *h )
+{
+ int i, j;
+ int i_mb_count = h->sps->i_mb_width * h->sps->i_mb_height;
+
+ h->mb.i_mb_stride = h->sps->i_mb_width;
+
+ h->mb.type= x264_malloc( i_mb_count * sizeof( int8_t) );
+ h->mb.qp = x264_malloc( i_mb_count * sizeof( int8_t) );
+ h->mb.cbp = x264_malloc( i_mb_count * sizeof( int16_t) );
+
+ /* 0 -> 3 top(4), 4 -> 6 : left(3) */
+ h->mb.intra4x4_pred_mode = x264_malloc( i_mb_count * 7 * sizeof( int8_t ) );
+
+ /* all coeffs */
+ h->mb.non_zero_count = x264_malloc( i_mb_count * 24 * sizeof( uint8_t ) );
+
+ h->mb.mv[0] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
+ h->mb.mv[1] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
+ h->mb.ref[0] = x264_malloc( 4 * i_mb_count * sizeof( int16_t ) );
+ h->mb.ref[1] = x264_malloc( 4 * i_mb_count * sizeof( int16_t ) );
+
+ if( h->param.b_cabac )
+ {
+ h->mb.chroma_pred_mode = x264_malloc( i_mb_count * sizeof( int8_t) );
+ h->mb.mvd[0] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
+ h->mb.mvd[1] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
+ }
+
+ for( i=0; i<2; i++ )
+ for( j=0; j<16; j++ ) /* FIXME: alloc no more than param.i_frame_reference */
+ h->mb.mvr[i][j] = x264_malloc( 2 * i_mb_count * sizeof( int16_t ) );
+
+ /* init with not avaiable (for top right idx=7,15) */
+ memset( h->mb.cache.ref[0], -2, X264_SCAN8_SIZE * sizeof( int8_t ) );
+ memset( h->mb.cache.ref[1], -2, X264_SCAN8_SIZE * sizeof( int8_t ) );
+}
+void x264_macroblock_cache_end( x264_t *h )
+{
+ int i, j;
+ for( i=0; i<2; i++ )
+ for( j=0; j<16; j++ )
+ x264_free( h->mb.mvr[i][j] );
+ if( h->param.b_cabac )
+ {
+ x264_free( h->mb.chroma_pred_mode );
+ x264_free( h->mb.mvd[0] );
+ x264_free( h->mb.mvd[1] );
+ }
+ x264_free( h->mb.mv[0] );
+ x264_free( h->mb.mv[1] );
+ x264_free( h->mb.ref[0] );
+ x264_free( h->mb.ref[1] );
+ x264_free( h->mb.intra4x4_pred_mode );
+ x264_free( h->mb.non_zero_count );
+ x264_free( h->mb.cbp );
+ x264_free( h->mb.qp );
+ x264_free( h->mb.type );
+}
+
+
+void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
+{
+ const int i_mb_4x4 = 16 * h->mb.i_mb_stride *i_mb_y + 4 * i_mb_x;
+ const int i_mb_8x8 = 4 * h->mb.i_mb_stride *i_mb_y + 2 * i_mb_x;
+
+ int i_top_xy = -1;
+ int i_left_xy = -1;
+ int i_top_type = -1; /* gcc warn */
+ int i_left_type= -1;
+
+ int i;
+
+ /* init index */
+ h->mb.i_mb_x = i_mb_x;
+ h->mb.i_mb_y = i_mb_y;
+ h->mb.i_mb_xy = i_mb_y * h->mb.i_mb_stride + i_mb_x;
+ h->mb.i_neighbour = 0;
+
+ /* load picture pointers */
+ for( i = 0; i < 3; i++ )
+ {
+ const int w = (i == 0 ? 16 : 8);
+ const int i_stride = h->fdec->i_stride[i];
+ int j;
+
+ h->mb.pic.i_stride[i] = i_stride;
+
+ h->mb.pic.p_fenc[i] = &h->fenc->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
+
+ h->mb.pic.p_fdec[i] = &h->fdec->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
+
+ for( j = 0; j < h->i_ref0; j++ )
+ {
+ h->mb.pic.p_fref[0][j][i] = &h->fref0[j]->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
+ }
+ for( j = 0; j < h->i_ref1; j++ )
+ {
+ h->mb.pic.p_fref[1][j][i] = &h->fref1[j]->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
+ }
+ }
+
+ /* load cache */
+ if( i_mb_y > 0 )
+ {
+ i_top_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
+ i_top_type= h->mb.type[i_top_xy];
+
+ h->mb.i_neighbour |= MB_TOP;
+
+ /* load intra4x4 */
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[0] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][0];
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[1] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][1];
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[4] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][2];
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[5] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][3];
+
+ /* load non_zero_count */
+ h->mb.cache.non_zero_count[x264_scan8[0] - 8] = h->mb.non_zero_count[i_top_xy][10];
+ h->mb.cache.non_zero_count[x264_scan8[1] - 8] = h->mb.non_zero_count[i_top_xy][11];
+ h->mb.cache.non_zero_count[x264_scan8[4] - 8] = h->mb.non_zero_count[i_top_xy][14];
+ h->mb.cache.non_zero_count[x264_scan8[5] - 8] = h->mb.non_zero_count[i_top_xy][15];
+
+ h->mb.cache.non_zero_count[x264_scan8[16+0] - 8] = h->mb.non_zero_count[i_top_xy][16+2];
+ h->mb.cache.non_zero_count[x264_scan8[16+1] - 8] = h->mb.non_zero_count[i_top_xy][16+3];
+
+ h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 8] = h->mb.non_zero_count[i_top_xy][16+4+2];
+ h->mb.cache.non_zero_count[x264_scan8[16+4+1] - 8] = h->mb.non_zero_count[i_top_xy][16+4+3];
+ }
+ else
+ {
+ /* load intra4x4 */
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[0] - 8] =
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[1] - 8] =
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[4] - 8] =
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[5] - 8] = -1;
+
+ /* load non_zero_count */
+ h->mb.cache.non_zero_count[x264_scan8[0] - 8] =
+ h->mb.cache.non_zero_count[x264_scan8[1] - 8] =
+ h->mb.cache.non_zero_count[x264_scan8[4] - 8] =
+ h->mb.cache.non_zero_count[x264_scan8[5] - 8] =
+ h->mb.cache.non_zero_count[x264_scan8[16+0] - 8] =
+ h->mb.cache.non_zero_count[x264_scan8[16+1] - 8] =
+ h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 8] =
+ h->mb.cache.non_zero_count[x264_scan8[16+4+1] - 8] = 0x80;
+
+ }
+
+ if( i_mb_x > 0 )
+ {
+ i_left_xy = h->mb.i_mb_xy - 1;
+ i_left_type= h->mb.type[i_left_xy];
+
+ h->mb.i_neighbour |= MB_LEFT;
+
+ /* load intra4x4 */
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[0 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][4];
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[2 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][5];
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[8 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][6];
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[10] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][3];
+
+ /* load non_zero_count */
+ h->mb.cache.non_zero_count[x264_scan8[0 ] - 1] = h->mb.non_zero_count[i_left_xy][5];
+ h->mb.cache.non_zero_count[x264_scan8[2 ] - 1] = h->mb.non_zero_count[i_left_xy][7];
+ h->mb.cache.non_zero_count[x264_scan8[8 ] - 1] = h->mb.non_zero_count[i_left_xy][13];
+ h->mb.cache.non_zero_count[x264_scan8[10] - 1] = h->mb.non_zero_count[i_left_xy][15];
+
+ h->mb.cache.non_zero_count[x264_scan8[16+0] - 1] = h->mb.non_zero_count[i_left_xy][16+1];
+ h->mb.cache.non_zero_count[x264_scan8[16+2] - 1] = h->mb.non_zero_count[i_left_xy][16+3];
+
+ h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 1] = h->mb.non_zero_count[i_left_xy][16+4+1];
+ h->mb.cache.non_zero_count[x264_scan8[16+4+2] - 1] = h->mb.non_zero_count[i_left_xy][16+4+3];
+ }
+ else
+ {
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[0 ] - 1] =
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[2 ] - 1] =
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[8 ] - 1] =
+ h->mb.cache.intra4x4_pred_mode[x264_scan8[10] - 1] = -1;
+
+ /* load non_zero_count */
+ h->mb.cache.non_zero_count[x264_scan8[0 ] - 1] =
+ h->mb.cache.non_zero_count[x264_scan8[2 ] - 1] =
+ h->mb.cache.non_zero_count[x264_scan8[8 ] - 1] =
+ h->mb.cache.non_zero_count[x264_scan8[10] - 1] =
+ h->mb.cache.non_zero_count[x264_scan8[16+0] - 1] =
+ h->mb.cache.non_zero_count[x264_scan8[16+2] - 1] =
+ h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 1] =
+ h->mb.cache.non_zero_count[x264_scan8[16+4+2] - 1] = 0x80;
+ }
+
+ if( i_mb_y > 0 && i_mb_x < h->sps->i_mb_width - 1 )
+ {
+ h->mb.i_neighbour |= MB_TOPRIGHT;
+ }
+
+ /* load ref/mv/mvd */
+ if( h->sh.i_type != SLICE_TYPE_I )
+ {
+ int s8x8 = 2 * h->mb.i_mb_stride;
+ int s4x4 = 4 * h->mb.i_mb_stride;
+
+ int i_top_left_xy = -1;
+ int i_top_right_xy = -1;
+
+ int i_list;
+
+ if( h->mb.i_mb_y > 0 && h->mb.i_mb_x > 0 )
+ {
+ i_top_left_xy = i_top_xy - 1;
+ }
+ if( h->mb.i_mb_y > 0 && h->mb.i_mb_x < h->sps->i_mb_width - 1 )
+ {
+ i_top_right_xy = i_top_xy + 1;
+ }
+
+ for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_P ? 1 : 2 ); i_list++ )
+ {
+ /*
+ h->mb.cache.ref[i_list][x264_scan8[5 ]+1] =
+ h->mb.cache.ref[i_list][x264_scan8[7 ]+1] =
+ h->mb.cache.ref[i_list][x264_scan8[13]+1] = -2;
+ */
+
+ if( i_top_left_xy >= 0 )
+ {
+ const int i8 = x264_scan8[0] - 1 - 1*8;
+ const int ir = i_mb_8x8 - s8x8 - 1;
+ const int iv = i_mb_4x4 - s4x4 - 1;
+ h->mb.cache.ref[i_list][i8] = h->mb.ref[i_list][ir];
+ h->mb.cache.mv[i_list][i8][0] = h->mb.mv[i_list][iv][0];
+ h->mb.cache.mv[i_list][i8][1] = h->mb.mv[i_list][iv][1];
+ }
+ else
+ {
+ const int i8 = x264_scan8[0] - 1 - 1*8;
+ h->mb.cache.ref[i_list][i8] = -2;
+ h->mb.cache.mv[i_list][i8][0] = 0;
+ h->mb.cache.mv[i_list][i8][1] = 0;
+ }
+
+ if( i_top_xy >= 0 )
+ {
+ const int i8 = x264_scan8[0] - 8;
+ const int ir = i_mb_8x8 - s8x8;
+ const int iv = i_mb_4x4 - s4x4;
+
+ h->mb.cache.ref[i_list][i8+0] =
+ h->mb.cache.ref[i_list][i8+1] = h->mb.ref[i_list][ir + 0];
+ h->mb.cache.ref[i_list][i8+2] =
+ h->mb.cache.ref[i_list][i8+3] = h->mb.ref[i_list][ir + 1];
+
+ for( i = 0; i < 4; i++ )
+ {
+ h->mb.cache.mv[i_list][i8+i][0] = h->mb.mv[i_list][iv + i][0];
+ h->mb.cache.mv[i_list][i8+i][1] = h->mb.mv[i_list][iv + i][1];
+ }
+ }
+ else
+ {
+ const int i8 = x264_scan8[0] - 8;
+ for( i = 0; i < 4; i++ )
+ {
+ h->mb.cache.ref[i_list][i8+i] = -2;
+ h->mb.cache.mv[i_list][i8+i][0] =
+ h->mb.cache.mv[i_list][i8+i][1] = 0;
+ }
+ }
+
+ if( i_top_right_xy >= 0 )
+ {
+ const int i8 = x264_scan8[0] + 4 - 1*8;
+ const int ir = i_mb_8x8 - s8x8 + 2;
+ const int iv = i_mb_4x4 - s4x4 + 4;
+
+ h->mb.cache.ref[i_list][i8] = h->mb.ref[i_list][ir];
+ h->mb.cache.mv[i_list][i8][0] = h->mb.mv[i_list][iv][0];
+ h->mb.cache.mv[i_list][i8][1] = h->mb.mv[i_list][iv][1];
+ }
+ else
+ {
+ const int i8 = x264_scan8[0] + 4 - 1*8;
+ h->mb.cache.ref[i_list][i8] = -2;
+ h->mb.cache.mv[i_list][i8][0] = 0;
+ h->mb.cache.mv[i_list][i8][1] = 0;
+ }
+
+ if( i_left_xy >= 0 )
+ {
+ const int i8 = x264_scan8[0] - 1;
+ const int ir = i_mb_8x8 - 1;
+ const int iv = i_mb_4x4 - 1;
+
+ h->mb.cache.ref[i_list][i8+0*8] =
+ h->mb.cache.ref[i_list][i8+1*8] = h->mb.ref[i_list][ir + 0*s8x8];
+ h->mb.cache.ref[i_list][i8+2*8] =
+ h->mb.cache.ref[i_list][i8+3*8] = h->mb.ref[i_list][ir + 1*s8x8];
+
+ for( i = 0; i < 4; i++ )
+ {
+ h->mb.cache.mv[i_list][i8+i*8][0] = h->mb.mv[i_list][iv + i*s4x4][0];
+ h->mb.cache.mv[i_list][i8+i*8][1] = h->mb.mv[i_list][iv + i*s4x4][1];
+ }
+ }
+ else
+ {
+ const int i8 = x264_scan8[0] - 1;
+ for( i = 0; i < 4; i++ )
+ {
+ h->mb.cache.ref[i_list][i8+i*8] = -2;
+ h->mb.cache.mv[i_list][i8+i*8][0] =
+ h->mb.cache.mv[i_list][i8+i*8][1] = 0;
+ }
+ }
+
+ if( h->param.b_cabac )
+ {
+ if( i_top_xy >= 0 )
+ {
+ const int i8 = x264_scan8[0] - 8;
+ const int iv = i_mb_4x4 - s4x4;
+ for( i = 0; i < 4; i++ )
+ {
+ h->mb.cache.mvd[i_list][i8+i][0] = h->mb.mvd[i_list][iv + i][0];
+ h->mb.cache.mvd[i_list][i8+i][1] = h->mb.mvd[i_list][iv + i][1];
+ }
+ }
+ else
+ {
+ const int i8 = x264_scan8[0] - 8;
+ for( i = 0; i < 4; i++ )
+ {
+ h->mb.cache.mvd[i_list][i8+i][0] =
+ h->mb.cache.mvd[i_list][i8+i][1] = 0;
+ }
+ }
+
+ if( i_left_xy >= 0 )
+ {
+ const int i8 = x264_scan8[0] - 1;
+ const int iv = i_mb_4x4 - 1;
+ for( i = 0; i < 4; i++ )
+ {
+ h->mb.cache.mvd[i_list][i8+i*8][0] = h->mb.mvd[i_list][iv + i*s4x4][0];
+ h->mb.cache.mvd[i_list][i8+i*8][1] = h->mb.mvd[i_list][iv + i*s4x4][1];
+ }
+ }
+ else
+ {
+ const int i8 = x264_scan8[0] - 1;
+ for( i = 0; i < 4; i++ )
+ {
+ h->mb.cache.mvd[i_list][i8+i*8][0] =
+ h->mb.cache.mvd[i_list][i8+i*8][1] = 0;
+ }
+ }
+ }
+ }
+ }
+}
+
+void x264_macroblock_cache_save( x264_t *h )
+{
+ const int i_mb_xy = h->mb.i_mb_xy;
+ const int i_mb_type = h->mb.i_type;
+ const int i_mb_4x4 = 16 * h->mb.i_mb_stride * h->mb.i_mb_y + 4 * h->mb.i_mb_x;
+ const int i_mb_8x8 = 4 * h->mb.i_mb_stride * h->mb.i_mb_y + 2 * h->mb.i_mb_x;
+
+ int i;
+
+ if( IS_SKIP( h->mb.i_type ) )
+ h->mb.qp[i_mb_xy] = h->mb.i_last_qp;
+
+ h->mb.i_last_dqp = h->mb.qp[i_mb_xy] - h->mb.i_last_qp;
+ h->mb.i_last_qp = h->mb.qp[i_mb_xy];
+
+ /* save intra4x4 */
+ if( i_mb_type == I_4x4 )
+ {
+ h->mb.intra4x4_pred_mode[i_mb_xy][0] = h->mb.cache.intra4x4_pred_mode[x264_scan8[10] ];
+ h->mb.intra4x4_pred_mode[i_mb_xy][1] = h->mb.cache.intra4x4_pred_mode[x264_scan8[11] ];
+ h->mb.intra4x4_pred_mode[i_mb_xy][2] = h->mb.cache.intra4x4_pred_mode[x264_scan8[14] ];
+ h->mb.intra4x4_pred_mode[i_mb_xy][3] = h->mb.cache.intra4x4_pred_mode[x264_scan8[15] ];
+ h->mb.intra4x4_pred_mode[i_mb_xy][4] = h->mb.cache.intra4x4_pred_mode[x264_scan8[5] ];
+ h->mb.intra4x4_pred_mode[i_mb_xy][5] = h->mb.cache.intra4x4_pred_mode[x264_scan8[7] ];
+ h->mb.intra4x4_pred_mode[i_mb_xy][6] = h->mb.cache.intra4x4_pred_mode[x264_scan8[13] ];
+ }
+ else
+ {
+ h->mb.intra4x4_pred_mode[i_mb_xy][0] =
+ h->mb.intra4x4_pred_mode[i_mb_xy][1] =
+ h->mb.intra4x4_pred_mode[i_mb_xy][2] =
+ h->mb.intra4x4_pred_mode[i_mb_xy][3] =
+ h->mb.intra4x4_pred_mode[i_mb_xy][4] =
+ h->mb.intra4x4_pred_mode[i_mb_xy][5] =
+ h->mb.intra4x4_pred_mode[i_mb_xy][6] = I_PRED_4x4_DC;
+ }
+
+ if( i_mb_type == I_PCM )
+ {
+ h->mb.cbp[i_mb_xy] = 0x72f; /* all set */
+ for( i = 0; i < 16 + 2*4; i++ )
+ {
+ h->mb.non_zero_count[i_mb_xy][i] = 16;
+ }
+ }
+ else
+ {
+ /* save non zero count */
+ for( i = 0; i < 16 + 2*4; i++ )
+ {
+ h->mb.non_zero_count[i_mb_xy][i] = h->mb.cache.non_zero_count[x264_scan8[i]];
+ }
+ }
+
+ if( !IS_INTRA( i_mb_type ) )
+ {
+ int i_list;
+ for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_P ? 1 : 2 ); i_list++ )
+ {
+ const int s8x8 = 2 * h->mb.i_mb_stride;
+ const int s4x4 = 4 * h->mb.i_mb_stride;
+ int y,x;
+
+ h->mb.ref[i_list][i_mb_8x8+0+0*s8x8] = h->mb.cache.ref[i_list][x264_scan8[0]];
+ h->mb.ref[i_list][i_mb_8x8+1+0*s8x8] = h->mb.cache.ref[i_list][x264_scan8[4]];
+ h->mb.ref[i_list][i_mb_8x8+0+1*s8x8] = h->mb.cache.ref[i_list][x264_scan8[8]];
+ h->mb.ref[i_list][i_mb_8x8+1+1*s8x8] = h->mb.cache.ref[i_list][x264_scan8[12]];
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][0] = h->mb.cache.mv[i_list][x264_scan8[0]+x+8*y][0];
+ h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][1] = h->mb.cache.mv[i_list][x264_scan8[0]+x+8*y][1];
+ }
+ }
+ }
+ }
+ else
+ {
+ int i_list;
+ for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_P ? 1 : 2 ); i_list++ )
+ {
+ const int s8x8 = 2 * h->mb.i_mb_stride;
+ const int s4x4 = 4 * h->mb.i_mb_stride;
+ int y,x;
+
+ h->mb.ref[i_list][i_mb_8x8+0+0*s8x8] =
+ h->mb.ref[i_list][i_mb_8x8+1+0*s8x8] =
+ h->mb.ref[i_list][i_mb_8x8+0+1*s8x8] =
+ h->mb.ref[i_list][i_mb_8x8+1+1*s8x8] = -1;
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][0] = 0;
+ h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][1] = 0;
+ }
+ }
+ }
+ }
+
+ if( h->param.b_cabac )
+ {
+ if( i_mb_type == I_4x4 || i_mb_type == I_16x16 )
+ h->mb.chroma_pred_mode[i_mb_xy] = h->mb.i_chroma_pred_mode;
+ else
+ h->mb.chroma_pred_mode[i_mb_xy] = I_PRED_CHROMA_DC;
+
+ if( !IS_INTRA( i_mb_type ) && !IS_SKIP( i_mb_type ) )
+ {
+ int i_list;
+ for( i_list = 0; i_list < 2; i_list++ )
+ {
+ const int s4x4 = 4 * h->mb.i_mb_stride;
+ int y,x;
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][0] = h->mb.cache.mvd[i_list][x264_scan8[0]+x+8*y][0];
+ h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][1] = h->mb.cache.mvd[i_list][x264_scan8[0]+x+8*y][1];
+ }
+ }
+ }
+ }
+ else
+ {
+ int i_list;
+ for( i_list = 0; i_list < 2; i_list++ )
+ {
+ const int s4x4 = 4 * h->mb.i_mb_stride;
+ int y,x;
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][0] = 0;
+ h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][1] = 0;
+ }
+ }
+ }
+ }
+ }
+}
+
--- /dev/null
+/*****************************************************************************
+ * macroblock.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: macroblock.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _MACROBLOCK_H
+#define _MACROBLOCK_H 1
+
+enum macroblock_position_e
+{
+ MB_LEFT = 0x01,
+ MB_TOP = 0x02,
+ MB_TOPRIGHT = 0x04,
+
+ MB_PRIVATE = 0x10,
+};
+
+
+/* XXX mb_type isn't the one written in the bitstream -> only internal usage */
+#define IS_INTRA(type) ( (type) == I_4x4 || (type) == I_16x16 )
+#define IS_SKIP(type) ( (type) == P_SKIP || (type) == B_SKIP )
+enum mb_class_e
+{
+ I_4x4 = 0,
+ I_16x16 = 1,
+ I_PCM = 2,
+
+ P_L0 = 3,
+ P_8x8 = 4,
+ P_SKIP = 5,
+
+ B_DIRECT = 6,
+ B_L0_L0 = 7,
+ B_L0_L1 = 8,
+ B_L0_BI = 9,
+ B_L1_L0 = 10,
+ B_L1_L1 = 11,
+ B_L1_BI = 12,
+ B_BI_L0 = 13,
+ B_BI_L1 = 14,
+ B_BI_BI = 15,
+ B_8x8 = 16,
+ B_SKIP = 17,
+};
+static const int x264_mb_type_list0_table[18][2] =
+{
+ {0,0}, {0,0}, {0,0}, /* INTRA */
+ {1,1}, /* P_L0 */
+ {0,0}, /* P_8x8 */
+ {1,1}, /* P_SKIP */
+ {0,0}, /* B_DIRECT */
+ {1,1}, {1,0}, {1,1}, /* B_L0_* */
+ {0,1}, {0,0}, {0,1}, /* B_L1_* */
+ {1,1}, {1,0}, {1,1}, /* B_BI_* */
+ {0,0}, /* B_8x8 */
+ {0,0} /* B_SKIP */
+};
+static const int x264_mb_type_list1_table[18][2] =
+{
+ {0,0}, {0,0}, {0,0}, /* INTRA */
+ {0,0}, /* P_L0 */
+ {0,0}, /* P_8x8 */
+ {0,0}, /* P_SKIP */
+ {0,0}, /* B_DIRECT */
+ {0,0}, {0,1}, {0,1}, /* B_L0_* */
+ {1,0}, {1,1}, {1,1}, /* B_L1_* */
+ {1,0}, {1,1}, {1,1}, /* B_BI_* */
+ {0,0}, /* B_8x8 */
+ {0,0} /* B_SKIP */
+};
+
+#define IS_SUB4x4(type) ( (type ==D_L0_4x4)||(type ==D_L1_4x4)||(type ==D_BI_4x4))
+#define IS_SUB4x8(type) ( (type ==D_L0_4x8)||(type ==D_L1_4x8)||(type ==D_BI_4x8))
+#define IS_SUB8x4(type) ( (type ==D_L0_8x4)||(type ==D_L1_8x4)||(type ==D_BI_8x4))
+#define IS_SUB8x8(type) ( (type ==D_L0_8x8)||(type ==D_L1_8x8)||(type ==D_BI_8x8)||(type ==D_DIRECT_8x8))
+enum mb_partition_e
+{
+ /* sub partition type for P_8x8 and B_8x8 */
+ D_L0_4x4 = 0,
+ D_L0_8x4 = 1,
+ D_L0_4x8 = 2,
+ D_L0_8x8 = 3,
+
+ /* sub partition type for B_8x8 only */
+ D_L1_4x4 = 4,
+ D_L1_8x4 = 5,
+ D_L1_4x8 = 6,
+ D_L1_8x8 = 7,
+
+ D_BI_4x4 = 8,
+ D_BI_8x4 = 9,
+ D_BI_4x8 = 10,
+ D_BI_8x8 = 11,
+ D_DIRECT_8x8 = 12,
+
+ /* partition */
+ D_8x8 = 13,
+ D_16x8 = 14,
+ D_8x16 = 15,
+ D_16x16 = 16,
+};
+
+static const int x264_mb_partition_count_table[17] =
+{
+ /* sub L0 */
+ 4, 2, 2, 1,
+ /* sub L1 */
+ 4, 2, 2, 1,
+ /* sub BI */
+ 4, 2, 2, 1,
+ /* Direct */
+ 1,
+ /* Partition */
+ 4, 2, 2, 1
+};
+
+void x264_macroblock_cache_init( x264_t *h );
+void x264_macroblock_cache_load( x264_t *h, int, int );
+void x264_macroblock_cache_save( x264_t *h );
+void x264_macroblock_cache_end( x264_t *h );
+
+void x264_mb_dequant_4x4_dc( int16_t dct[4][4], int i_qscale );
+void x264_mb_dequant_2x2_dc( int16_t dct[2][2], int i_qscale );
+void x264_mb_dequant_4x4( int16_t dct[4][4], int i_qscale );
+
+/* x264_mb_predict_mv_16x16:
+ * set mvp with predicted mv for D_16x16 block
+ * h->mb. need only valid values from other blocks */
+void x264_mb_predict_mv_16x16( x264_t *h, int i_list, int i_ref, int mvp[2] );
+/* x264_mb_predict_mv_pskip:
+ * set mvp with predicted mv for P_SKIP
+ * h->mb. need only valid values from other blocks */
+void x264_mb_predict_mv_pskip( x264_t *h, int mv[2] );
+/* x264_mb_predict_mv:
+ * set mvp with predicted mv for all blocks except P_SKIP
+ * h->mb. need valid ref/partition/sub of current block to be valid
+ * and valid mv/ref from other blocks . */
+void x264_mb_predict_mv( x264_t *h, int i_list, int idx, int i_width, int mvp[2] );
+/* x264_mb_predict_mv_ref16x16:
+ * set mvc with D_16x16 prediction.
+ * uses all neighbors, even those that didn't end up using this ref.
+ * need only valid values from other blocks */
+void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int mvc[4][2], int *i_mvc );
+
+
+int x264_mb_predict_intra4x4_mode( x264_t *h, int idx );
+int x264_mb_predict_non_zero_code( x264_t *h, int idx );
+
+void x264_mb_encode_i4x4( x264_t *h, int idx, int i_qscale );
+
+void x264_mb_mc( x264_t *h );
+
+
+static inline void x264_macroblock_cache_ref( x264_t *h, int x, int y, int width, int height, int i_list, int ref )
+{
+ int dy, dx;
+ for( dy = 0; dy < height; dy++ )
+ {
+ for( dx = 0; dx < width; dx++ )
+ {
+ h->mb.cache.ref[i_list][X264_SCAN8_0+x+dx+8*(y+dy)] = ref;
+ }
+ }
+}
+static inline void x264_macroblock_cache_mv( x264_t *h, int x, int y, int width, int height, int i_list, int mvx, int mvy )
+{
+ int dy, dx;
+ for( dy = 0; dy < height; dy++ )
+ {
+ for( dx = 0; dx < width; dx++ )
+ {
+ h->mb.cache.mv[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][0] = mvx;
+ h->mb.cache.mv[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][1] = mvy;
+ }
+ }
+}
+static inline void x264_macroblock_cache_mvd( x264_t *h, int x, int y, int width, int height, int i_list, int mdx, int mdy )
+{
+ int dy, dx;
+ for( dy = 0; dy < height; dy++ )
+ {
+ for( dx = 0; dx < width; dx++ )
+ {
+ h->mb.cache.mvd[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][0] = mdx;
+ h->mb.cache.mvd[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][1] = mdy;
+ }
+ }
+}
+
+#endif
+
--- /dev/null
+/*****************************************************************************
+ * mc.c: h264 encoder library (Motion Compensation)
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: mc.c,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "../x264.h"
+
+#include "mc.h"
+#include "clip1.h"
+
+#ifdef _MSC_VER
+#undef HAVE_MMXEXT /* not finished now */
+#endif
+#ifdef HAVE_MMXEXT
+# include "i386/mc.h"
+#endif
+#ifdef ARCH_PPC
+# include "ppc/mc.h"
+#endif
+
+
+static inline int x264_tapfilter( uint8_t *pix, int i_pix_next )
+{
+ return pix[-2*i_pix_next] - 5*pix[-1*i_pix_next] + 20*(pix[0] + pix[1*i_pix_next]) - 5*pix[ 2*i_pix_next] + pix[ 3*i_pix_next];
+}
+static inline int x264_tapfilter1( uint8_t *pix )
+{
+ return pix[-2] - 5*pix[-1] + 20*(pix[0] + pix[1]) - 5*pix[ 2] + pix[ 3];
+}
+
+static inline void pixel_avg( uint8_t *dst, int i_dst_stride,
+ uint8_t *src1, int i_src1_stride,
+ uint8_t *src2, int i_src2_stride,
+ int i_width, int i_height )
+{
+ int x, y;
+ for( y = 0; y < i_height; y++ )
+ {
+ for( x = 0; x < i_width; x++ )
+ {
+ dst[x] = ( src1[x] + src2[x] + 1 ) >> 1;
+ }
+ dst += i_dst_stride;
+ src1 += i_src1_stride;
+ src2 += i_src2_stride;
+ }
+}
+
+typedef void (*pf_mc_t)(uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height );
+
+static void mc_copy( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ int y;
+
+ for( y = 0; y < i_height; y++ )
+ {
+ memcpy( dst, src, i_width );
+
+ src += i_src_stride;
+ dst += i_dst_stride;
+ }
+}
+static inline void mc_hh( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ int x, y;
+
+ for( y = 0; y < i_height; y++ )
+ {
+ for( x = 0; x < i_width; x++ )
+ {
+ dst[x] = x264_mc_clip1( ( x264_tapfilter1( &src[x] ) + 16 ) >> 5 );
+ }
+ src += i_src_stride;
+ dst += i_dst_stride;
+ }
+}
+static inline void mc_hv( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ int x, y;
+
+ for( y = 0; y < i_height; y++ )
+ {
+ for( x = 0; x < i_width; x++ )
+ {
+ dst[x] = x264_mc_clip1( ( x264_tapfilter( &src[x], i_src_stride ) + 16 ) >> 5 );
+ }
+ src += i_src_stride;
+ dst += i_dst_stride;
+ }
+}
+static inline void mc_hc( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t *out;
+ uint8_t *pix;
+ int x, y;
+
+ for( x = 0; x < i_width; x++ )
+ {
+ int tap[6];
+
+ pix = &src[x];
+ out = &dst[x];
+
+ tap[0] = x264_tapfilter1( &pix[-2*i_src_stride] );
+ tap[1] = x264_tapfilter1( &pix[-1*i_src_stride] );
+ tap[2] = x264_tapfilter1( &pix[ 0*i_src_stride] );
+ tap[3] = x264_tapfilter1( &pix[ 1*i_src_stride] );
+ tap[4] = x264_tapfilter1( &pix[ 2*i_src_stride] );
+
+ for( y = 0; y < i_height; y++ )
+ {
+ tap[5] = x264_tapfilter1( &pix[ 3*i_src_stride] );
+
+ *out = x264_mc_clip1( ( tap[0] - 5*tap[1] + 20 * tap[2] + 20 * tap[3] -5*tap[4] + tap[5] + 512 ) >> 10 );
+
+ /* Next line */
+ pix += i_src_stride;
+ out += i_dst_stride;
+ tap[0] = tap[1];
+ tap[1] = tap[2];
+ tap[2] = tap[3];
+ tap[3] = tap[4];
+ tap[4] = tap[5];
+ }
+ }
+}
+
+/* mc I+H */
+static void mc_xy10( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp[16*16];
+ mc_hh( src, i_src_stride, tmp, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, src, i_src_stride, tmp, i_width, i_width, i_height );
+}
+static void mc_xy30( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp[16*16];
+ mc_hh( src, i_src_stride, tmp, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, src+1, i_src_stride, tmp, i_width, i_width, i_height );
+}
+/* mc I+V */
+static void mc_xy01( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp[16*16];
+ mc_hv( src, i_src_stride, tmp, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, src, i_src_stride, tmp, i_width, i_width, i_height );
+}
+static void mc_xy03( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp[16*16];
+ mc_hv( src, i_src_stride, tmp, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, src+i_src_stride, i_src_stride, tmp, i_width, i_width, i_height );
+}
+/* H+V */
+static void mc_xy11( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+
+ mc_hv( src, i_src_stride, tmp1, i_width, i_width, i_height );
+ mc_hh( src, i_src_stride, tmp2, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
+}
+static void mc_xy31( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+
+ mc_hv( src+1, i_src_stride, tmp1, i_width, i_width, i_height );
+ mc_hh( src, i_src_stride, tmp2, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
+}
+static void mc_xy13( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+
+ mc_hv( src, i_src_stride, tmp1, i_width, i_width, i_height );
+ mc_hh( src+i_src_stride, i_src_stride, tmp2, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
+}
+static void mc_xy33( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+
+ mc_hv( src+1, i_src_stride, tmp1, i_width, i_width, i_height );
+ mc_hh( src+i_src_stride, i_src_stride, tmp2, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
+}
+static void mc_xy21( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+
+ mc_hc( src, i_src_stride, tmp1, i_width, i_width, i_height );
+ mc_hh( src, i_src_stride, tmp2, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
+}
+static void mc_xy12( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+
+ mc_hc( src, i_src_stride, tmp1, i_width, i_width, i_height );
+ mc_hv( src, i_src_stride, tmp2, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
+}
+static void mc_xy32( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+
+ mc_hc( src, i_src_stride, tmp1, i_width, i_width, i_height );
+ mc_hv( src+1, i_src_stride, tmp2, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
+}
+static void mc_xy23( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+
+ mc_hc( src, i_src_stride, tmp1, i_width, i_width, i_height );
+ mc_hh( src+i_src_stride, i_src_stride, tmp2, i_width, i_width, i_height );
+ pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
+}
+
+static void motion_compensation_luma( uint8_t *src, int i_src_stride,
+ uint8_t *dst, int i_dst_stride,
+ int mvx,int mvy,
+ int i_width, int i_height )
+{
+ static pf_mc_t pf_mc[4][4] = /*XXX [dqy][dqx] */
+ {
+ { mc_copy, mc_xy10, mc_hh, mc_xy30 },
+ { mc_xy01, mc_xy11, mc_xy21, mc_xy31 },
+ { mc_hv, mc_xy12, mc_hc, mc_xy32 },
+ { mc_xy03, mc_xy13, mc_xy23, mc_xy33 },
+ };
+
+ src += (mvy >> 2) * i_src_stride + (mvx >> 2);
+ pf_mc[mvy&0x03][mvx&0x03]( src, i_src_stride, dst, i_dst_stride, i_width, i_height );
+}
+
+/* full chroma mc (ie until 1/8 pixel)*/
+static void motion_compensation_chroma( uint8_t *src, int i_src_stride,
+ uint8_t *dst, int i_dst_stride,
+ int mvx, int mvy,
+ int i_width, int i_height )
+{
+ uint8_t *srcp;
+ int x, y;
+
+ const int d8x = mvx&0x07;
+ const int d8y = mvy&0x07;
+
+ const int cA = (8-d8x)*(8-d8y);
+ const int cB = d8x *(8-d8y);
+ const int cC = (8-d8x)*d8y;
+ const int cD = d8x *d8y;
+
+ src += (mvy >> 3) * i_src_stride + (mvx >> 3);
+ srcp = &src[i_src_stride];
+
+ for( y = 0; y < i_height; y++ )
+ {
+ for( x = 0; x < i_width; x++ )
+ {
+ dst[x] = ( cA*src[x] + cB*src[x+1] +
+ cC*srcp[x] + cD*srcp[x+1] + 32 ) >> 6;
+ }
+ dst += i_dst_stride;
+
+ src = srcp;
+ srcp += i_src_stride;
+ }
+}
+
+void x264_mc_init( int cpu, x264_mc_function_t pf[2] )
+{
+ pf[MC_LUMA] = motion_compensation_luma;
+ pf[MC_CHROMA] = motion_compensation_chroma;
+
+#ifdef HAVE_MMXEXT
+ if( cpu&X264_CPU_MMXEXT )
+ x264_mc_mmxext_init( pf );
+#endif
+#ifdef HAVE_SSE2
+ if( cpu&X264_CPU_SSE2 )
+ x264_mc_sse2_init( pf );
+#endif
+
+#ifdef ARCH_PPC
+ if( cpu&X264_CPU_ALTIVEC )
+ x264_mc_altivec_init( pf );
+#endif
+}
+
--- /dev/null
+/*****************************************************************************
+ * mc.h: h264 encoder library (Motion Compensation)
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: mc.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _MC_H
+#define _MC_H 1
+
+/* Do the MC
+ * XXX: Only width = 4, 8 or 16 are valid
+ * width == 4 -> height == 4 or 8
+ * width == 8 -> height == 4 or 8 or 16
+ * width == 16-> height == 8 or 16
+ * */
+
+typedef void (*x264_mc_function_t)(uint8_t *, int, uint8_t *, int,
+ int mvx, int mvy,
+ int i_width, int i_height );
+enum
+{
+ MC_LUMA = 0,
+ MC_CHROMA = 1,
+};
+
+void x264_mc_init( int cpu, x264_mc_function_t pf[2] );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * mdate.c: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: mdate.c,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+
+#if !(defined(_MSC_VER) || defined(__MINGW32__))
+#include <sys/time.h>
+#else
+#include <sys/types.h>
+#include <sys/timeb.h>
+#endif
+#include <time.h>
+
+int64_t x264_mdate( void )
+{
+#if !(defined(_MSC_VER) || defined(__MINGW32__))
+ struct timeval tv_date;
+
+ gettimeofday( &tv_date, NULL );
+ return( (int64_t) tv_date.tv_sec * 1000000 + (int64_t) tv_date.tv_usec );
+#else
+ struct _timeb tb;
+ _ftime(&tb);
+ return ((int64_t)tb.time * (1000) + (int64_t)tb.millitm) * (1000);
+#endif
+}
+
--- /dev/null
+/*****************************************************************************
+ * pixel.c: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: pixel.c,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "../x264.h"
+#include "pixel.h"
+
+#ifdef HAVE_MMXEXT
+# include "i386/pixel.h"
+#endif
+#ifdef ARCH_PPC
+# include "ppc/pixel.h"
+#endif
+
+
+/****************************************************************************
+ * pixel_sad_WxH
+ ****************************************************************************/
+#define PIXEL_SAD_C( name, lx, ly ) \
+static int name( uint8_t *pix1, int i_stride_pix1, \
+ uint8_t *pix2, int i_stride_pix2 ) \
+{ \
+ int i_sum = 0; \
+ int x, y; \
+ for( y = 0; y < ly; y++ ) \
+ { \
+ for( x = 0; x < lx; x++ ) \
+ { \
+ i_sum += abs( pix1[x] - pix2[x] ); \
+ } \
+ pix1 += i_stride_pix1; \
+ pix2 += i_stride_pix2; \
+ } \
+ return i_sum; \
+}
+
+
+PIXEL_SAD_C( pixel_sad_16x16, 16, 16 )
+PIXEL_SAD_C( pixel_sad_16x8, 16, 8 )
+PIXEL_SAD_C( pixel_sad_8x16, 8, 16 )
+PIXEL_SAD_C( pixel_sad_8x8, 8, 8 )
+PIXEL_SAD_C( pixel_sad_8x4, 8, 4 )
+PIXEL_SAD_C( pixel_sad_4x8, 4, 8 )
+PIXEL_SAD_C( pixel_sad_4x4, 4, 4 )
+
+static void pixel_sub_4x4( int16_t diff[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
+{
+ int y, x;
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ diff[y][x] = pix1[x] - pix2[x];
+ }
+ pix1 += i_pix1;
+ pix2 += i_pix2;
+ }
+}
+
+static int pixel_satd_wxh( uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2, int i_width, int i_height )
+{
+ int16_t tmp[4][4];
+ int16_t diff[4][4];
+ int x, y;
+ int i_satd = 0;
+
+ for( y = 0; y < i_height; y += 4 )
+ {
+ for( x = 0; x < i_width; x += 4 )
+ {
+ int d;
+
+ pixel_sub_4x4( diff, &pix1[x], i_pix1, &pix2[x], i_pix2 );
+
+ for( d = 0; d < 4; d++ )
+ {
+ int s01, s23;
+ int d01, d23;
+
+ s01 = diff[d][0] + diff[d][1]; s23 = diff[d][2] + diff[d][3];
+ d01 = diff[d][0] - diff[d][1]; d23 = diff[d][2] - diff[d][3];
+
+ tmp[d][0] = s01 + s23;
+ tmp[d][1] = s01 - s23;
+ tmp[d][2] = d01 - d23;
+ tmp[d][3] = d01 + d23;
+ }
+ for( d = 0; d < 4; d++ )
+ {
+ int s01, s23;
+ int d01, d23;
+
+ s01 = tmp[0][d] + tmp[1][d]; s23 = tmp[2][d] + tmp[3][d];
+ d01 = tmp[0][d] - tmp[1][d]; d23 = tmp[2][d] - tmp[3][d];
+
+ i_satd += abs( s01 + s23 ) + abs( s01 - s23 ) + abs( d01 - d23 ) + abs( d01 + d23 );
+ }
+
+ }
+ pix1 += 4 * i_pix1;
+ pix2 += 4 * i_pix2;
+ }
+
+ return i_satd / 2;
+}
+#define PIXEL_SATD_C( name, width, height ) \
+static int name( uint8_t *pix1, int i_stride_pix1, \
+ uint8_t *pix2, int i_stride_pix2 ) \
+{ \
+ return pixel_satd_wxh( pix1, i_stride_pix1, pix2, i_stride_pix2, width, height ); \
+}
+PIXEL_SATD_C( pixel_satd_16x16, 16, 16 )
+PIXEL_SATD_C( pixel_satd_16x8, 16, 8 )
+PIXEL_SATD_C( pixel_satd_8x16, 8, 16 )
+PIXEL_SATD_C( pixel_satd_8x8, 8, 8 )
+PIXEL_SATD_C( pixel_satd_8x4, 8, 4 )
+PIXEL_SATD_C( pixel_satd_4x8, 4, 8 )
+PIXEL_SATD_C( pixel_satd_4x4, 4, 4 )
+
+
+static inline void pixel_avg_wxh( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int width, int height )
+{
+ int x, y;
+ for( y = 0; y < height; y++ )
+ {
+ for( x = 0; x < width; x++ )
+ {
+ dst[x] = ( dst[x] + src[x] + 1 ) >> 1;
+ }
+ dst += i_dst;
+ src += i_src;
+ }
+}
+
+
+#define PIXEL_AVG_C( name, width, height ) \
+static void name( uint8_t *pix1, int i_stride_pix1, \
+ uint8_t *pix2, int i_stride_pix2 ) \
+{ \
+ pixel_avg_wxh( pix1, i_stride_pix1, pix2, i_stride_pix2, width, height ); \
+}
+PIXEL_AVG_C( pixel_avg_16x16, 16, 16 )
+PIXEL_AVG_C( pixel_avg_16x8, 16, 8 )
+PIXEL_AVG_C( pixel_avg_8x16, 8, 16 )
+PIXEL_AVG_C( pixel_avg_8x8, 8, 8 )
+PIXEL_AVG_C( pixel_avg_8x4, 8, 4 )
+PIXEL_AVG_C( pixel_avg_4x8, 4, 8 )
+PIXEL_AVG_C( pixel_avg_4x4, 4, 4 )
+
+/****************************************************************************
+ * x264_pixel_init:
+ ****************************************************************************/
+void x264_pixel_init( int cpu, x264_pixel_function_t *pixf )
+{
+ pixf->sad[PIXEL_16x16] = pixel_sad_16x16;
+ pixf->sad[PIXEL_16x8] = pixel_sad_16x8;
+ pixf->sad[PIXEL_8x16] = pixel_sad_8x16;
+ pixf->sad[PIXEL_8x8] = pixel_sad_8x8;
+ pixf->sad[PIXEL_8x4] = pixel_sad_8x4;
+ pixf->sad[PIXEL_4x8] = pixel_sad_4x8;
+ pixf->sad[PIXEL_4x4] = pixel_sad_4x4;
+
+ pixf->satd[PIXEL_16x16]= pixel_satd_16x16;
+ pixf->satd[PIXEL_16x8] = pixel_satd_16x8;
+ pixf->satd[PIXEL_8x16] = pixel_satd_8x16;
+ pixf->satd[PIXEL_8x8] = pixel_satd_8x8;
+ pixf->satd[PIXEL_8x4] = pixel_satd_8x4;
+ pixf->satd[PIXEL_4x8] = pixel_satd_4x8;
+ pixf->satd[PIXEL_4x4] = pixel_satd_4x4;
+
+ pixf->avg[PIXEL_16x16]= pixel_avg_16x16;
+ pixf->avg[PIXEL_16x8] = pixel_avg_16x8;
+ pixf->avg[PIXEL_8x16] = pixel_avg_8x16;
+ pixf->avg[PIXEL_8x8] = pixel_avg_8x8;
+ pixf->avg[PIXEL_8x4] = pixel_avg_8x4;
+ pixf->avg[PIXEL_4x8] = pixel_avg_4x8;
+ pixf->avg[PIXEL_4x4] = pixel_avg_4x4;
+#ifdef HAVE_MMXEXT
+ if( cpu&X264_CPU_MMXEXT )
+ {
+ pixf->sad[PIXEL_16x16] = x264_pixel_sad_16x16_mmxext;
+ pixf->sad[PIXEL_16x8 ] = x264_pixel_sad_16x8_mmxext;
+ pixf->sad[PIXEL_8x16 ] = x264_pixel_sad_8x16_mmxext;
+ pixf->sad[PIXEL_8x8 ] = x264_pixel_sad_8x8_mmxext;
+ pixf->sad[PIXEL_8x4 ] = x264_pixel_sad_8x4_mmxext;
+ pixf->sad[PIXEL_4x8 ] = x264_pixel_sad_4x8_mmxext;
+ pixf->sad[PIXEL_4x4] = x264_pixel_sad_4x4_mmxext;
+
+ pixf->satd[PIXEL_16x16]= x264_pixel_satd_16x16_mmxext;
+ pixf->satd[PIXEL_16x8] = x264_pixel_satd_16x8_mmxext;
+ pixf->satd[PIXEL_8x16] = x264_pixel_satd_8x16_mmxext;
+ pixf->satd[PIXEL_8x8] = x264_pixel_satd_8x8_mmxext;
+ pixf->satd[PIXEL_8x4] = x264_pixel_satd_8x4_mmxext;
+ pixf->satd[PIXEL_4x8] = x264_pixel_satd_4x8_mmxext;
+ pixf->satd[PIXEL_4x4] = x264_pixel_satd_4x4_mmxext;
+ }
+#endif
+#ifdef ARCH_PPC
+ if( cpu&X264_CPU_ALTIVEC )
+ {
+ x264_pixel_altivec_init( pixf );
+ }
+#endif
+}
+
--- /dev/null
+/*****************************************************************************
+ * pixel.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: pixel.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _PIXEL_H
+#define _PIXEL_H 1
+
+typedef int (*x264_pixel_sad_t) ( uint8_t *, int, uint8_t *, int );
+typedef int (*x264_pixel_satd_t)( uint8_t *, int, uint8_t *, int );
+typedef void (*x264_pixel_avg_t) ( uint8_t *, int, uint8_t *, int );
+
+enum
+{
+ PIXEL_16x16 = 0,
+ PIXEL_16x8 = 1,
+ PIXEL_8x16 = 2,
+ PIXEL_8x8 = 3,
+ PIXEL_8x4 = 4,
+ PIXEL_4x8 = 5,
+ PIXEL_4x4 = 6,
+};
+
+static const struct {
+ int w;
+ int h;
+} x264_pixel_size[7] = {
+ { 16, 16 },
+ { 16, 8 }, { 8, 16 },
+ { 8, 8 },
+ { 8, 4 }, { 4, 8 },
+ { 4, 4 }
+};
+
+typedef struct
+{
+ x264_pixel_sad_t sad[7];
+ x264_pixel_satd_t satd[7];
+ x264_pixel_avg_t avg[7];
+} x264_pixel_function_t;
+
+void x264_pixel_init( int cpu, x264_pixel_function_t *pixf );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * mc.c: h264 encoder library (Motion Compensation)
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: mc.c,v 1.1 2004/06/03 19:27:07 fenrir Exp $
+ *
+ * Authors: Eric Petit <titer@m0k.org>
+ *
+ * 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 <stdarg.h>
+
+#ifdef SYS_LINUX
+#include <altivec.h>
+#endif
+
+#include "x264.h"
+#include "../mc.h"
+#include "../clip1.h"
+#include "mc.h"
+#include "ppccommon.h"
+
+typedef void (*pf_mc_t)( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height );
+
+static inline int x264_tapfilter( uint8_t *pix, int i_pix_next )
+{
+ return pix[-2*i_pix_next] - 5*pix[-1*i_pix_next] + 20*(pix[0] +
+ pix[1*i_pix_next]) - 5*pix[ 2*i_pix_next] +
+ pix[ 3*i_pix_next];
+}
+static inline int x264_tapfilter1( uint8_t *pix )
+{
+ return pix[-2] - 5*pix[-1] + 20*(pix[0] + pix[1]) - 5*pix[ 2] +
+ pix[ 3];
+}
+
+/* pixel_avg */
+static inline void pixel_avg_w4( uint8_t *dst, int i_dst,
+ uint8_t *src1, int i_src1,
+ uint8_t *src2, int i_src2,
+ int i_height )
+{
+ int x, y;
+ for( y = 0; y < i_height; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ dst[x] = ( src1[x] + src2[x] + 1 ) >> 1;
+ }
+ dst += i_dst;
+ src1 += i_src1;
+ src2 += i_src2;
+ }
+}
+static inline void pixel_avg_w8( uint8_t *dst, int i_dst,
+ uint8_t *src1, int i_src1,
+ uint8_t *src2, int i_src2,
+ int i_height )
+{
+ /* TODO - optimize */
+ pixel_avg_w4( &dst[0], i_dst, &src1[0], i_src1, &src2[0], i_src2,
+ i_height );
+ pixel_avg_w4( &dst[4], i_dst, &src1[4], i_src1, &src2[4], i_src2,
+ i_height );
+}
+static inline void pixel_avg_w16( uint8_t *dst, int i_dst,
+ uint8_t *src1, int i_src1,
+ uint8_t *src2, int i_src2,
+ int i_height )
+{
+ int y;
+ vector_u8_t src1v, src2v;
+ for( y = 0; y < i_height; y++ )
+ {
+ LOAD_16( src1, src1v );
+ LOAD_16( src2, src2v );
+ src1v = vec_avg( src1v, src2v );
+ STORE_16( src1v, dst );
+
+ dst += i_dst;
+ src1 += i_src1;
+ src2 += i_src2;
+ }
+}
+
+/* mc_copy: plain c */
+#define MC_COPY( name, a ) \
+static void name( uint8_t *src, int i_src, \
+ uint8_t *dst, int i_dst, int i_height ) \
+{ \
+ int y; \
+ for( y = 0; y < i_height; y++ ) \
+ { \
+ memcpy( dst, src, a ); \
+ src += i_src; \
+ dst += i_dst; \
+ } \
+}
+MC_COPY( mc_copy_w4, 4 )
+MC_COPY( mc_copy_w8, 8 )
+MC_COPY( mc_copy_w16, 16 )
+
+/* TAP_FILTER:
+ a is source (vector_s16_t [6])
+ b is a temporary vector_s16_t
+ c is the result
+
+ c = src[0] + a[5] - 5 * ( a[1] + a[4] ) + 20 * ( a[2] + a[3] );
+ c += 16;
+ c >>= 5;
+ c += 80; */
+#define TAP_FILTER( a, b, c ) \
+ c = vec_add( a[0], a[5] ); \
+ b = vec_add( a[1], a[4] ); \
+ c = vec_sub( c, b ); \
+ b = vec_sl( b, vec_splat_u16( 2 ) ); \
+ c = vec_sub( c, b ); \
+ b = vec_add( a[2], a[3] ); \
+ b = vec_sl( b, vec_splat_u16( 2 ) ); \
+ c = vec_add( c, b ); \
+ b = vec_sl( b, vec_splat_u16( 2 ) ); \
+ c = vec_add( c, b ); \
+ c = vec_add( c, vec_splat_s16( 8 ) ); \
+ c = vec_add( c, vec_splat_s16( 8 ) ); \
+ c = vec_sr( c, vec_splat_u16( 5 ) ); \
+ c = vec_add( c, vec_sl( vec_splat_s16( 5 ), \
+ vec_splat_u16( 4 ) ) );
+
+/* mc_hh */
+static inline void mc_hh_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ int x, y;
+ for( y = 0; y < i_height; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ dst[x] = x264_mc_clip1( ( x264_tapfilter1( &src[x] ) +
+ 16 ) >> 5 );
+ }
+ src += i_src;
+ dst += i_dst;
+ }
+}
+static inline void mc_hh_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ long x, y;
+ DECLARE_ALIGNED( int16_t, tmp[8], 16 );
+
+ LOAD_ZERO;
+ vector_u8_t loadv;
+ vector_s16_t srcv[6];
+ vector_u8_t * _srcv = (vector_u8_t*) srcv;
+ vector_s16_t dstv;
+ vector_s16_t tmpv;
+
+ for( y = 0; y < i_height; y++ )
+ {
+ LOAD_16( &src[-2], loadv );
+
+ for( x = 0; x < 6; x++ )
+ {
+ _srcv[x] = vec_perm( loadv, zero_u8,
+ vec_lvsl( 0, (int*) x ) );
+ CONVERT_U8_TO_S16( srcv[x] );
+ }
+
+ TAP_FILTER( srcv, tmpv, dstv );
+ vec_st( dstv, 0, tmp );
+
+ for( x = 0; x < 8; x++ )
+ {
+ dst[x] = x264_mc_clip1_table[tmp[x]];
+ }
+
+ src += i_src;
+ dst += i_dst;
+ }
+}
+static inline void mc_hh_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ mc_hh_w8( &src[0], i_src, &dst[0], i_dst, i_height );
+ mc_hh_w8( &src[8], i_src, &dst[8], i_dst, i_height );
+}
+
+/* mc_hv */
+static inline void mc_hv_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ int x, y;
+ for( y = 0; y < i_height; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ dst[x] = x264_mc_clip1( ( x264_tapfilter( &src[x], i_src ) +
+ 16 ) >> 5 );
+ }
+ src += i_src;
+ dst += i_dst;
+ }
+}
+static inline void mc_hv_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ int x, y;
+ DECLARE_ALIGNED( int16_t, tmp[8], 16 );
+
+ LOAD_ZERO;
+ vector_s16_t srcv[6];
+ vector_u8_t * _srcv = (vector_u8_t*) srcv;
+ vector_s16_t dstv;
+ vector_s16_t tmpv;
+
+ for( y = 0; y < i_height; y++ )
+ {
+ if( y )
+ {
+ for( x = 0; x < 5; x++ )
+ {
+ srcv[x] = srcv[x+1];
+ }
+ LOAD_8( &src[3*i_src], _srcv[5] );
+ CONVERT_U8_TO_S16( srcv[5] );
+ }
+ else
+ {
+ for( x = 0; x < 6; x++ )
+ {
+ LOAD_8( &src[(x-2)*i_src], _srcv[x] );
+ CONVERT_U8_TO_S16( srcv[x] );
+ }
+ }
+
+ TAP_FILTER( srcv, tmpv, dstv );
+ vec_st( dstv, 0, tmp );
+
+ for( x = 0; x < 8; x++ )
+ {
+ dst[x] = x264_mc_clip1_table[tmp[x]];
+ }
+ src += i_src;
+ dst += i_dst;
+ }
+}
+static inline void mc_hv_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ mc_hv_w8( &src[0], i_src, &dst[0], i_dst, i_height );
+ mc_hv_w8( &src[8], i_src, &dst[8], i_dst, i_height );
+}
+
+/* mc_hc */
+static inline void mc_hc_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t *out;
+ uint8_t *pix;
+ int x, y;
+
+ for( x = 0; x < 4; x++ )
+ {
+ int tap[6];
+
+ pix = &src[x];
+ out = &dst[x];
+
+ tap[0] = x264_tapfilter1( &pix[-2*i_src] );
+ tap[1] = x264_tapfilter1( &pix[-1*i_src] );
+ tap[2] = x264_tapfilter1( &pix[ 0*i_src] );
+ tap[3] = x264_tapfilter1( &pix[ 1*i_src] );
+ tap[4] = x264_tapfilter1( &pix[ 2*i_src] );
+
+ for( y = 0; y < i_height; y++ )
+ {
+ tap[5] = x264_tapfilter1( &pix[ 3*i_src] );
+
+ *out = x264_mc_clip1( ( tap[0] - 5*tap[1] + 20 * tap[2] +
+ 20 * tap[3] -5*tap[4] + tap[5] +
+ 512 ) >> 10 );
+
+ /* Next line */
+ pix += i_src;
+ out += i_dst;
+ tap[0] = tap[1];
+ tap[1] = tap[2];
+ tap[2] = tap[3];
+ tap[3] = tap[4];
+ tap[4] = tap[5];
+ }
+ }
+}
+static inline void mc_hc_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ /* TODO: optimize */
+ mc_hc_w4( &src[0], i_src, &dst[0], i_dst, i_height );
+ mc_hc_w4( &src[4], i_src, &dst[4], i_dst, i_height );
+}
+static inline void mc_hc_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ mc_hc_w8( &src[0], i_src, &dst[0], i_dst, i_height );
+ mc_hc_w8( &src[8], i_src, &dst[8], i_dst, i_height );
+}
+
+/* mc I+H */
+static void mc_xy10_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*4];
+ mc_hh_w4( src, i_src, tmp, 4, i_height );
+ pixel_avg_w4( dst, i_dst, src, i_src, tmp, 4, i_height );
+}
+static void mc_xy10_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*8];
+ mc_hh_w8( src, i_src, tmp, 8, i_height );
+ pixel_avg_w8( dst, i_dst, src, i_src, tmp, 8, i_height );
+}
+static void mc_xy10_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*16];
+ mc_hh_w16( src, i_src, tmp, 16, i_height );
+ pixel_avg_w16( dst, i_dst, src, i_src, tmp, 16, i_height );
+}
+
+static void mc_xy30_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*4];
+ mc_hh_w4( src, i_src, tmp, 4, i_height );
+ pixel_avg_w4( dst, i_dst, src + 1, i_src, tmp, 4, i_height );
+}
+static void mc_xy30_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*8];
+ mc_hh_w8( src, i_src, tmp, 8, i_height );
+ pixel_avg_w8( dst, i_dst, src + 1, i_src, tmp, 8, i_height );
+}
+static void mc_xy30_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*16];
+ mc_hh_w16( src, i_src, tmp, 16, i_height );
+ pixel_avg_w16( dst, i_dst, src + 1, i_src, tmp, 16, i_height );
+}
+
+/* mc I+V */
+static void mc_xy01_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*4];
+ mc_hv_w4( src, i_src, tmp, 4, i_height );
+ pixel_avg_w4( dst, i_dst, src, i_src, tmp, 4, i_height );
+}
+static void mc_xy01_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*8];
+ mc_hv_w8( src, i_src, tmp, 8, i_height );
+ pixel_avg_w8( dst, i_dst, src, i_src, tmp, 8, i_height );
+}
+static void mc_xy01_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*16];
+ mc_hv_w16( src, i_src, tmp, 16, i_height );
+ pixel_avg_w16( dst, i_dst, src, i_src, tmp, 16, i_height );
+}
+
+static void mc_xy03_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*4];
+ mc_hv_w4( src, i_src, tmp, 4, i_height );
+ pixel_avg_w4( dst, i_dst, src + i_src, i_src, tmp, 4, i_height );
+}
+static void mc_xy03_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*8];
+ mc_hv_w8( src, i_src, tmp, 8, i_height );
+ pixel_avg_w8( dst, i_dst, src + i_src, i_src, tmp, 8, i_height );
+}
+static void mc_xy03_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp[16*16];
+ mc_hv_w16( src, i_src, tmp, 16, i_height );
+ pixel_avg_w16( dst, i_dst, src + i_src, i_src, tmp, 16, i_height );
+}
+
+/* H+V */
+static void mc_xy11_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*4];
+ uint8_t tmp2[16*4];
+ mc_hv_w4( src, i_src, tmp1, 4, i_height );
+ mc_hh_w4( src, i_src, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy11_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*8];
+ uint8_t tmp2[16*8];
+ mc_hv_w8( src, i_src, tmp1, 8, i_height );
+ mc_hh_w8( src, i_src, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy11_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+ mc_hv_w16( src, i_src, tmp1, 16, i_height );
+ mc_hh_w16( src, i_src, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
+}
+
+static void mc_xy31_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*4];
+ uint8_t tmp2[16*4];
+ mc_hv_w4( src+1, i_src, tmp1, 4, i_height );
+ mc_hh_w4( src, i_src, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy31_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*8];
+ uint8_t tmp2[16*8];
+ mc_hv_w8( src+1, i_src, tmp1, 8, i_height );
+ mc_hh_w8( src, i_src, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy31_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+ mc_hv_w16( src+1, i_src, tmp1, 16, i_height );
+ mc_hh_w16( src, i_src, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
+}
+
+static void mc_xy13_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*4];
+ uint8_t tmp2[16*4];
+ mc_hv_w4( src, i_src, tmp1, 4, i_height );
+ mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy13_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*8];
+ uint8_t tmp2[16*8];
+ mc_hv_w8( src, i_src, tmp1, 8, i_height );
+ mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy13_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+ mc_hv_w16( src, i_src, tmp1, 16, i_height );
+ mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
+}
+
+static void mc_xy33_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*4];
+ uint8_t tmp2[16*4];
+ mc_hv_w4( src+1, i_src, tmp1, 4, i_height );
+ mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy33_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*8];
+ uint8_t tmp2[16*8];
+ mc_hv_w8( src+1, i_src, tmp1, 8, i_height );
+ mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy33_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+ mc_hv_w16( src+1, i_src, tmp1, 16, i_height );
+ mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
+}
+
+static void mc_xy21_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*4];
+ uint8_t tmp2[16*4];
+ mc_hc_w4( src, i_src, tmp1, 4, i_height );
+ mc_hh_w4( src, i_src, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy21_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*8];
+ uint8_t tmp2[16*8];
+ mc_hc_w8( src, i_src, tmp1, 8, i_height );
+ mc_hh_w8( src, i_src, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy21_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+ mc_hc_w16( src, i_src, tmp1, 16, i_height );
+ mc_hh_w16( src, i_src, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
+}
+
+static void mc_xy12_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*4];
+ uint8_t tmp2[16*4];
+ mc_hc_w4( src, i_src, tmp1, 4, i_height );
+ mc_hv_w4( src, i_src, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy12_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*8];
+ uint8_t tmp2[16*8];
+ mc_hc_w8( src, i_src, tmp1, 8, i_height );
+ mc_hv_w8( src, i_src, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy12_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+ mc_hc_w16( src, i_src, tmp1, 16, i_height );
+ mc_hv_w16( src, i_src, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
+}
+
+static void mc_xy32_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*4];
+ uint8_t tmp2[16*4];
+ mc_hc_w4( src, i_src, tmp1, 4, i_height );
+ mc_hv_w4( src+1, i_src, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy32_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*8];
+ uint8_t tmp2[16*8];
+ mc_hc_w8( src, i_src, tmp1, 8, i_height );
+ mc_hv_w8( src+1, i_src, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy32_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+ mc_hc_w16( src, i_src, tmp1, 16, i_height );
+ mc_hv_w16( src+1, i_src, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
+}
+
+static void mc_xy23_w4( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*4];
+ uint8_t tmp2[16*4];
+ mc_hc_w4( src, i_src, tmp1, 4, i_height );
+ mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
+ pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
+}
+static void mc_xy23_w8( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*8];
+ uint8_t tmp2[16*8];
+ mc_hc_w8( src, i_src, tmp1, 8, i_height );
+ mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
+ pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
+}
+static void mc_xy23_w16( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst, int i_height )
+{
+ uint8_t tmp1[16*16];
+ uint8_t tmp2[16*16];
+ mc_hc_w16( src, i_src, tmp1, 16, i_height );
+ mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
+ pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
+}
+
+static void motion_compensation_luma( uint8_t *src, int i_src,
+ uint8_t *dst, int i_dst,
+ int mvx,int mvy,
+ int i_width, int i_height )
+{
+ static const pf_mc_t pf_mc[3][4][4] = /*XXX [dqy][dqx] */
+ {
+ {
+ { mc_copy_w4, mc_xy10_w4, mc_hh_w4, mc_xy30_w4 },
+ { mc_xy01_w4, mc_xy11_w4, mc_xy21_w4, mc_xy31_w4 },
+ { mc_hv_w4, mc_xy12_w4, mc_hc_w4, mc_xy32_w4 },
+ { mc_xy03_w4, mc_xy13_w4, mc_xy23_w4, mc_xy33_w4 },
+ },
+ {
+ { mc_copy_w8, mc_xy10_w8, mc_hh_w8, mc_xy30_w8 },
+ { mc_xy01_w8, mc_xy11_w8, mc_xy21_w8, mc_xy31_w8 },
+ { mc_hv_w8, mc_xy12_w8, mc_hc_w8, mc_xy32_w8 },
+ { mc_xy03_w8, mc_xy13_w8, mc_xy23_w8, mc_xy33_w8 },
+ },
+ {
+ { mc_copy_w16, mc_xy10_w16, mc_hh_w16, mc_xy30_w16 },
+ { mc_xy01_w16, mc_xy11_w16, mc_xy21_w16, mc_xy31_w16 },
+ { mc_hv_w16, mc_xy12_w16, mc_hc_w16, mc_xy32_w16 },
+ { mc_xy03_w16, mc_xy13_w16, mc_xy23_w16, mc_xy33_w16 },
+ }
+ };
+
+ src += (mvy >> 2) * i_src + (mvx >> 2);
+ if( i_width == 4 )
+ {
+ pf_mc[0][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
+ }
+ else if( i_width == 8 )
+ {
+ pf_mc[1][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
+ }
+ else if( i_width == 16 )
+ {
+ pf_mc[2][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
+ }
+}
+
+void x264_mc_altivec_init( x264_mc_function_t pf[2] )
+{
+ pf[MC_LUMA] = motion_compensation_luma;
+}
--- /dev/null
+/*****************************************************************************
+ * mc.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: mc.h,v 1.1 2004/06/03 19:27:07 fenrir Exp $
+ *
+ * Authors: Eric Petit <titer@m0k.org>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifndef _PPC_MC_H
+#define _PPC_MC_H 1
+
+void x264_mc_altivec_init( x264_mc_function_t pf[2] );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * pixel.c: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: pixel.c,v 1.1 2004/06/03 19:27:07 fenrir Exp $
+ *
+ * Authors: Eric Petit <titer@m0k.org>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdarg.h>
+
+#ifdef SYS_LINUX
+#include <altivec.h>
+#endif
+
+#include "x264.h"
+#include "../pixel.h"
+#include "pixel.h"
+#include "ppccommon.h"
+
+/* sad routines */
+#define PIXEL_SAD_ALTIVEC( name, lx, ly, a, b ) \
+static int name( uint8_t *pix1, int i_pix1, \
+ uint8_t *pix2, int i_pix2 ) \
+{ \
+ int y; \
+ DECLARE_ALIGNED( int, sum, 16 ); \
+ \
+ LOAD_ZERO; \
+ vector_u8_t pix1v, pix2v; \
+ vector_s32_t sumv = zero_s32; \
+ for( y = 0; y < ly; y++ ) \
+ { \
+ LOAD_##lx( pix1, pix1v ); \
+ LOAD_##lx( pix2, pix2v ); \
+ sumv = (vector_s32_t) vec_sum4s( \
+ vec_sub( vec_max( pix1v, pix2v ), \
+ vec_min( pix1v, pix2v ) ), \
+ (vector_u32_t) sumv ); \
+ pix1 += i_pix1; \
+ pix2 += i_pix2; \
+ } \
+ sumv = vec_sum##a( sumv, zero_s32 ); \
+ vec_ste( vec_splat( sumv, b ), 0, &sum ); \
+ return sum; \
+}
+
+PIXEL_SAD_ALTIVEC( pixel_sad_16x16_altivec, 16, 16, s, 3 )
+PIXEL_SAD_ALTIVEC( pixel_sad_8x16_altivec, 8, 16, 2s, 1 )
+PIXEL_SAD_ALTIVEC( pixel_sad_16x8_altivec, 16, 8, s, 3 )
+PIXEL_SAD_ALTIVEC( pixel_sad_8x8_altivec, 8, 8, 2s, 1 )
+
+/* satd routines */
+static inline int pixel_satd_8x8_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
+{
+ int i;
+ DECLARE_ALIGNED( int, i_satd, 16 );
+
+ LOAD_ZERO;
+ vector_s32_t satdv = zero_s32;
+ vector_u8_t pix1u8v, pix2u8v;
+ vector_s16_t pix1s16v, pix2s16v;
+ vector_s16_t diffv[8];
+ vector_s16_t tmpv[8];
+ vector_s16_t s01v, s23v, d01v, d23v;
+
+ /* Diff 8x8 */
+ for( i = 0; i < 8; i++ )
+ {
+ LOAD_8( pix1, pix1u8v );
+ LOAD_8( pix2, pix2u8v );
+
+ /* u8 -> s16 conversion */
+ pix1s16v = (vector_s16_t) vec_mergeh( zero_u8, pix1u8v );
+ pix2s16v = (vector_s16_t) vec_mergeh( zero_u8, pix2u8v );
+
+ diffv[i] = vec_sub( pix1s16v, pix2s16v );
+
+ pix1 += i_pix1;
+ pix2 += i_pix2;
+ }
+
+ /* Hadamar H */
+ HADAMAR( &diffv[0], &tmpv[0] );
+ HADAMAR( &diffv[4], &tmpv[4] );
+
+ /* Transpose */
+ TRANSPOSE8x8( tmpv, diffv );
+
+ /* Hadamar V */
+ HADAMAR( &diffv[0], &tmpv[0] );
+ HADAMAR( &diffv[4], &tmpv[4] );
+
+ /* Sum of absolute values */
+ for( i = 0; i < 8; i++ )
+ {
+ satdv = vec_sum4s( vec_abs( tmpv[i] ), satdv );
+ }
+ satdv = vec_sums( satdv, zero_s32 );
+
+ /* Done */
+ vec_ste( vec_splat( satdv, 3 ), 0, &i_satd );
+ return i_satd / 2;
+}
+
+static int pixel_satd_16x8_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
+{
+ return pixel_satd_8x8_altivec( &pix1[0], i_pix1,
+ &pix2[0], i_pix2 ) +
+ pixel_satd_8x8_altivec( &pix1[8], i_pix1,
+ &pix2[8], i_pix2 );
+}
+static int pixel_satd_8x16_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
+{
+ return pixel_satd_8x8_altivec( &pix1[0], i_pix1,
+ &pix2[0], i_pix2 ) +
+ pixel_satd_8x8_altivec( &pix1[8*i_pix1], i_pix1,
+ &pix2[8*i_pix2], i_pix2 );
+}
+static int pixel_satd_16x16_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
+{
+ return pixel_satd_8x8_altivec( &pix1[0], i_pix1,
+ &pix2[0], i_pix2 ) +
+ pixel_satd_8x8_altivec( &pix1[8], i_pix1,
+ &pix2[8], i_pix2 ) +
+ pixel_satd_8x8_altivec( &pix1[8*i_pix1], i_pix1,
+ &pix2[8*i_pix2], i_pix2 ) +
+ pixel_satd_8x8_altivec( &pix1[8*i_pix1+8], i_pix1,
+ &pix2[8*i_pix2+8], i_pix2 );
+}
+
+static inline int pixel_satd_4x4_altivec( uint8_t *pix1, int i_pix1,
+ uint8_t *pix2, int i_pix2 )
+{
+ int i;
+ DECLARE_ALIGNED( int, i_satd, 16 );
+
+ LOAD_ZERO;
+ vector_s32_t satdv = zero_s32;
+ vector_u8_t pix1u8v, pix2u8v;
+ vector_s16_t pix1s16v, pix2s16v;
+ vector_s16_t diffv[4];
+ vector_s16_t tmpv[4];
+ vector_s16_t s01v, s23v, d01v, d23v;
+
+ /* Diff 4x8 */
+ for( i = 0; i < 4; i++ )
+ {
+ LOAD_4( pix1, pix1u8v );
+ LOAD_4( pix2, pix2u8v );
+
+ /* u8 -> s16 conversion */
+ pix1s16v = (vector_s16_t) vec_mergeh( zero_u8, pix1u8v );
+ pix2s16v = (vector_s16_t) vec_mergeh( zero_u8, pix2u8v );
+
+ diffv[i] = vec_sub( pix1s16v, pix2s16v );
+
+ pix1 += i_pix1;
+ pix2 += i_pix2;
+ }
+
+ /* Hadamar H */
+ HADAMAR( diffv, tmpv );
+
+ /* Transpose */
+ TRANSPOSE4x4( tmpv, diffv );
+
+ /* Hadamar V */
+ HADAMAR( diffv, tmpv );
+
+ /* Sum of absolute values */
+ for( i = 0; i < 4; i++ )
+ {
+ satdv = vec_sum4s( vec_abs( tmpv[i] ), satdv );
+ }
+ satdv = vec_sum2s( satdv, zero_s32 );
+
+ /* Done */
+ vec_ste( vec_splat( satdv, 1 ), 0, &i_satd );
+ return i_satd / 2;
+}
+
+/****************************************************************************
+ * x264_pixel_init:
+ ****************************************************************************/
+void x264_pixel_altivec_init( x264_pixel_function_t *pixf )
+{
+ pixf->sad[PIXEL_16x16] = pixel_sad_16x16_altivec;
+ pixf->sad[PIXEL_8x16] = pixel_sad_8x16_altivec;
+ pixf->sad[PIXEL_16x8] = pixel_sad_16x8_altivec;
+ pixf->sad[PIXEL_8x8] = pixel_sad_8x8_altivec;
+
+ pixf->satd[PIXEL_16x16] = pixel_satd_16x16_altivec;
+ pixf->satd[PIXEL_8x16] = pixel_satd_8x16_altivec;
+ pixf->satd[PIXEL_16x8] = pixel_satd_16x8_altivec;
+ pixf->satd[PIXEL_8x8] = pixel_satd_8x8_altivec;
+ pixf->satd[PIXEL_4x4] = pixel_satd_4x4_altivec;
+}
--- /dev/null
+/*****************************************************************************
+ * mc.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: pixel.h,v 1.1 2004/06/03 19:27:07 fenrir Exp $
+ *
+ * Authors: Eric Petit <titer@m0k.org>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifndef _PPC_PIXEL_H
+#define _PPC_PIXEL_H 1
+
+void x264_pixel_altivec_init( x264_pixel_function_t *pixf );
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * ppccommon.h: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: ppccommon.h,v 1.1 2004/06/03 19:27:07 fenrir Exp $
+ *
+ * Authors: Eric Petit <titer@m0k.org>
+ *
+ * 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.
+ *****************************************************************************/
+
+/* Handy */
+#define vector_u8_t vector unsigned char
+#define vector_s16_t vector signed short
+#define vector_u32_t vector unsigned int
+#define vector_s32_t vector signed int
+
+#define LOAD_ZERO vector_s32_t zero = vec_splat_s32( 0 )
+#define zero_u8 (vector_u8_t) zero
+#define zero_s16 (vector_s16_t) zero
+#define zero_s32 (vector_s32_t) zero
+
+#define CONVERT_U8_TO_S16( a ) \
+ a = (vector_s16_t) vec_mergeh( zero_u8, (vector_u8_t) a )
+
+/* Macros to load aligned or unaligned data without risking buffer
+ overflows. */
+#define LOAD_16( p, v ) \
+ if( (long) p & 0xF ) \
+ { \
+ v = vec_perm( vec_ld( 0, p ), vec_ld( 16, p ), \
+ vec_lvsl( 0, p ) ); \
+ } \
+ else \
+ { \
+ v = vec_ld( 0, p ); \
+ }
+
+#define LOAD_8( p, v ) \
+ if( !( (long) p & 0xF ) ) \
+ { \
+ v = vec_ld( 0, p ); \
+ } \
+ else if( ( (long) p & 0xF ) < 9 ) \
+ { \
+ v = vec_perm( vec_ld( 0, p ), (vector unsigned char) zero, \
+ vec_lvsl( 0, p ) ); \
+ } \
+ else \
+ { \
+ v = vec_perm( vec_ld( 0, p ), vec_ld( 16, p ), \
+ vec_lvsl( 0, p ) ); \
+ }
+
+#define LOAD_4( p, v ) \
+ if( !( (long) p & 0xF ) ) \
+ { \
+ v = vec_ld( 0, p ); \
+ } \
+ else if( ( (long) p & 0xF ) < 13 ) \
+ { \
+ v = vec_perm( vec_ld( 0, p ), (vector unsigned char) zero, \
+ vec_lvsl( 0, p ) ); \
+ } \
+ else \
+ { \
+ v = vec_perm( vec_ld( 0, p ), vec_ld( 16, p ), \
+ vec_lvsl( 0, p ) ); \
+ }
+
+/* Store aligned or unaligned data */
+#define STORE_16( v, p ) \
+ if( (long) p & 0xF ) \
+ { \
+ vector unsigned char tmp1, tmp2; \
+ vector unsigned char align, mask; \
+ tmp1 = vec_ld( 0, p ); \
+ tmp2 = vec_ld( 16, p ); \
+ align = vec_lvsr( 0, p ); \
+ mask = vec_perm( (vector unsigned char) {0}, \
+ (vector unsigned char) {1}, \
+ align); \
+ v = vec_perm( v, v, align); \
+ tmp1 = vec_sel( tmp1, v, mask ); \
+ tmp2 = vec_sel( v, tmp2, mask ); \
+ vec_st( tmp1, 0, p ); \
+ vec_st( tmp2, 16, p ); \
+ } \
+ else \
+ { \
+ vec_st( v, 0, p ); \
+ }
+
+/* Transpose 8x8 (vector_s16_t [8]) */
+#define TRANSPOSE8x8( a, b ) \
+ b[0] = vec_mergeh( a[0], a[4] ); \
+ b[1] = vec_mergel( a[0], a[4] ); \
+ b[2] = vec_mergeh( a[1], a[5] ); \
+ b[3] = vec_mergel( a[1], a[5] ); \
+ b[4] = vec_mergeh( a[2], a[6] ); \
+ b[5] = vec_mergel( a[2], a[6] ); \
+ b[6] = vec_mergeh( a[3], a[7] ); \
+ b[7] = vec_mergel( a[3], a[7] ); \
+ a[0] = vec_mergeh( b[0], b[4] ); \
+ a[1] = vec_mergel( b[0], b[4] ); \
+ a[2] = vec_mergeh( b[1], b[5] ); \
+ a[3] = vec_mergel( b[1], b[5] ); \
+ a[4] = vec_mergeh( b[2], b[6] ); \
+ a[5] = vec_mergel( b[2], b[6] ); \
+ a[6] = vec_mergeh( b[3], b[7] ); \
+ a[7] = vec_mergel( b[3], b[7] ); \
+ b[0] = vec_mergeh( a[0], a[4] ); \
+ b[1] = vec_mergel( a[0], a[4] ); \
+ b[2] = vec_mergeh( a[1], a[5] ); \
+ b[3] = vec_mergel( a[1], a[5] ); \
+ b[4] = vec_mergeh( a[2], a[6] ); \
+ b[5] = vec_mergel( a[2], a[6] ); \
+ b[6] = vec_mergeh( a[3], a[7] ); \
+ b[7] = vec_mergel( a[3], a[7] );
+
+/* Transpose 4x4 (vector_s16_t [4]) */
+#define TRANSPOSE4x4( a, b ) \
+ (b)[0] = vec_mergeh( (a)[0], zero_s16 ); \
+ (b)[1] = vec_mergeh( (a)[1], zero_s16 ); \
+ (b)[2] = vec_mergeh( (a)[2], zero_s16 ); \
+ (b)[3] = vec_mergeh( (a)[3], zero_s16 ); \
+ (a)[0] = vec_mergeh( (b)[0], (b)[2] ); \
+ (a)[1] = vec_mergel( (b)[0], (b)[2] ); \
+ (a)[2] = vec_mergeh( (b)[1], (b)[3] ); \
+ (a)[3] = vec_mergel( (b)[1], (b)[3] ); \
+ (b)[0] = vec_mergeh( (a)[0], (a)[2] ); \
+ (b)[1] = vec_mergel( (a)[0], (a)[2] ); \
+ (b)[2] = vec_mergeh( (a)[1], (a)[3] ); \
+ (b)[3] = vec_mergel( (a)[1], (a)[3] );
+
+/* Hadamar (vector_s16_t [4]) */
+#define HADAMAR( a, b ) \
+ s01v = vec_add( (a)[0], (a)[1] ); \
+ s23v = vec_add( (a)[2], (a)[3] ); \
+ d01v = vec_sub( (a)[0], (a)[1] ); \
+ d23v = vec_sub( (a)[2], (a)[3] ); \
+ (b)[0] = vec_add( s01v, s23v ); \
+ (b)[1] = vec_sub( s01v, s23v ); \
+ (b)[2] = vec_sub( d01v, d23v ); \
+ (b)[3] = vec_add( d01v, d23v );
+
--- /dev/null
+/*****************************************************************************
+ * predict.c: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: predict.c,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+/* XXX predict4x4 are inspired from ffmpeg h264 decoder
+ */
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "x264.h"
+#include "predict.h"
+
+#ifdef _MSC_VER
+#undef HAVE_MMXEXT /* not finished now */
+#endif
+#ifdef HAVE_MMXEXT
+# include "i386/predict.h"
+#endif
+
+static inline int clip_uint8( int a )
+{
+ if (a&(~255))
+ return (-a)>>31;
+ else
+ return a;
+}
+
+/****************************************************************************
+ * 16x16 prediction for intra block DC, H, V, P
+ ****************************************************************************/
+static void predict_16x16_dc( uint8_t *src, int i_stride )
+{
+ int dc = 0;
+ int i, j;
+
+ /* calculate DC value */
+ for( i = 0; i < 16; i++ )
+ {
+ dc += src[-1 + i * i_stride];
+ dc += src[i - i_stride];
+ }
+ dc = ( dc + 16 ) >> 5;
+
+ for( i = 0; i < 16; i++ )
+ {
+ for( j = 0; j < 16; j++ )
+ {
+ src[j] = dc;
+ }
+ src += i_stride;
+ }
+}
+static void predict_16x16_dc_left( uint8_t *src, int i_stride )
+{
+ int dc = 0;
+ int i,j;
+
+ for( i = 0; i < 16; i++ )
+ {
+ dc += src[-1 + i * i_stride];
+ }
+ dc = ( dc + 8 ) >> 4;
+
+ for( i = 0; i < 16; i++ )
+ {
+ for( j = 0; j < 16; j++ )
+ {
+ src[j] = dc;
+ }
+ src += i_stride;
+ }
+}
+static void predict_16x16_dc_top( uint8_t *src, int i_stride )
+{
+ int dc = 0;
+ int i,j;
+
+ for( i = 0; i < 16; i++ )
+ {
+ dc += src[i - i_stride];
+ }
+ dc = ( dc + 8 ) >> 4;
+
+ for( i = 0; i < 16; i++ )
+ {
+ for( j = 0; j < 16; j++ )
+ {
+ src[j] = dc;
+ }
+ src += i_stride;
+ }
+}
+static void predict_16x16_dc_128( uint8_t *src, int i_stride )
+{
+ int i,j;
+
+ for( i = 0; i < 16; i++ )
+ {
+ for( j = 0; j < 16; j++ )
+ {
+ src[j] = 128;
+ }
+ src += i_stride;
+ }
+}
+static void predict_16x16_h( uint8_t *src, int i_stride )
+{
+ int i,j;
+
+ for( i = 0; i < 16; i++ )
+ {
+ uint8_t v;
+
+ v = src[-1];
+ for( j = 0; j < 16; j++ )
+ {
+ src[j] = v;
+ }
+ src += i_stride;
+
+ }
+}
+static void predict_16x16_v( uint8_t *src, int i_stride )
+{
+ int i,j;
+
+ for( i = 0; i < 16; i++ )
+ {
+ for( j = 0; j < 16; j++ )
+ {
+ src[i * i_stride +j] = src[j - i_stride];
+ }
+ }
+}
+static void predict_16x16_p( uint8_t *src, int i_stride )
+{
+ int x, y, i;
+ int a, b, c;
+ int H = 0;
+ int V = 0;
+ int i00;
+
+ /* calcule H and V */
+ for( i = 0; i <= 7; i++ )
+ {
+ H += ( i + 1 ) * ( src[ 8 + i - i_stride ] - src[6 -i -i_stride] );
+ V += ( i + 1 ) * ( src[-1 + (8+i)*i_stride] - src[-1 + (6-i)*i_stride] );
+ }
+
+ a = 16 * ( src[-1 + 15*i_stride] + src[15 - i_stride] );
+ b = ( 5 * H + 32 ) >> 6;
+ c = ( 5 * V + 32 ) >> 6;
+
+ i00 = a - b * 7 - c * 7 + 16;
+
+ for( y = 0; y < 16; y++ )
+ {
+ for( x = 0; x < 16; x++ )
+ {
+ int pix;
+
+ pix = (i00+b*x)>>5;
+
+ src[x] = clip_uint8( pix );
+ }
+ src += i_stride;
+ i00 += c;
+ }
+}
+
+
+/****************************************************************************
+ * 8x8 prediction for intra chroma block DC, H, V, P
+ ****************************************************************************/
+static void predict_8x8_dc_128( uint8_t *src, int i_stride )
+{
+ int x,y;
+
+ for( y = 0; y < 8; y++ )
+ {
+ for( x = 0; x < 8; x++ )
+ {
+ src[x] = 128;
+ }
+ src += i_stride;
+ }
+}
+static void predict_8x8_dc_left( uint8_t *src, int i_stride )
+{
+ int x,y;
+ int dc0 = 0, dc1 = 0;
+
+ for( y = 0; y < 4; y++ )
+ {
+ dc0 += src[y * i_stride - 1];
+ dc1 += src[(y+4) * i_stride - 1];
+ }
+ dc0 = ( dc0 + 2 ) >> 2;
+ dc1 = ( dc1 + 2 ) >> 2;
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 8; x++ )
+ {
+ src[ x] = dc0;
+ src[4*i_stride+x] = dc1;
+ }
+ src += i_stride;
+ }
+}
+static void predict_8x8_dc_top( uint8_t *src, int i_stride )
+{
+ int x,y;
+ int dc0 = 0, dc1 = 0;
+
+ for( x = 0; x < 4; x++ )
+ {
+ dc0 += src[x - i_stride];
+ dc1 += src[x + 4 - i_stride];
+ }
+ dc0 = ( dc0 + 2 ) >> 2;
+ dc1 = ( dc1 + 2 ) >> 2;
+
+ for( y = 0; y < 8; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ src[x ] = dc0;
+ src[x + 4] = dc1;
+ }
+ src += i_stride;
+ }
+}
+static void predict_8x8_dc( uint8_t *src, int i_stride )
+{
+ int x,y;
+ int s0 = 0, s1 = 0, s2 = 0, s3 = 0;
+ int dc0, dc1, dc2, dc3;
+ int i;
+
+ /* First do :
+ s0 s1
+ s2
+ s3
+ */
+ for( i = 0; i < 4; i++ )
+ {
+ s0 += src[i - i_stride];
+ s1 += src[i + 4 - i_stride];
+ s2 += src[-1 + i * i_stride];
+ s3 += src[-1 + (i+4)*i_stride];
+ }
+ /* now calculate
+ dc0 dc1
+ dc2 dc3
+ */
+ dc0 = ( s0 + s2 + 4 ) >> 3;
+ dc1 = ( s1 + 2 ) >> 2;
+ dc2 = ( s3 + 2 ) >> 2;
+ dc3 = ( s1 + s3 + 4 ) >> 3;
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ src[ x ] = dc0;
+ src[ x + 4] = dc1;
+ src[4*i_stride + x ] = dc2;
+ src[4*i_stride + x + 4] = dc3;
+ }
+ src += i_stride;
+ }
+}
+
+static void predict_8x8_h( uint8_t *src, int i_stride )
+{
+ int i,j;
+
+ for( i = 0; i < 8; i++ )
+ {
+ uint8_t v;
+
+ v = src[-1];
+
+ for( j = 0; j < 8; j++ )
+ {
+ src[j] = v;
+ }
+ src += i_stride;
+ }
+}
+static void predict_8x8_v( uint8_t *src, int i_stride )
+{
+ int i,j;
+
+ for( i = 0; i < 8; i++ )
+ {
+ for( j = 0; j < 8; j++ )
+ {
+ src[i * i_stride +j] = src[j - i_stride];
+ }
+ }
+}
+
+static void predict_8x8_p( uint8_t *src, int i_stride )
+{
+ int i;
+ int x,y;
+ int a, b, c;
+ int H = 0;
+ int V = 0;
+ int i00;
+
+ for( i = 0; i < 4; i++ )
+ {
+ H += ( i + 1 ) * ( src[4+i - i_stride] - src[2 - i -i_stride] );
+ V += ( i + 1 ) * ( src[-1 +(i+4)*i_stride] - src[-1+(2-i)*i_stride] );
+ }
+
+ a = 16 * ( src[-1+7*i_stride] + src[7 - i_stride] );
+ b = ( 17 * H + 16 ) >> 5;
+ c = ( 17 * V + 16 ) >> 5;
+ i00 = a -3*b -3*c + 16;
+
+ for( y = 0; y < 8; y++ )
+ {
+ for( x = 0; x < 8; x++ )
+ {
+ int pix;
+
+ pix = (i00 +b*x) >> 5;
+ src[x] = clip_uint8( pix );
+ }
+ src += i_stride;
+ i00 += c;
+ }
+}
+
+/****************************************************************************
+ * 4x4 prediction for intra luma block DC, H, V, P
+ ****************************************************************************/
+static void predict_4x4_dc_128( uint8_t *src, int i_stride )
+{
+ int x,y;
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ src[x] = 128;
+ }
+ src += i_stride;
+ }
+}
+static void predict_4x4_dc_left( uint8_t *src, int i_stride )
+{
+ int x,y;
+ int dc = ( src[-1+0*i_stride] + src[-1+i_stride]+
+ src[-1+2*i_stride] + src[-1+3*i_stride] + 2 ) >> 2;
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ src[x] = dc;
+ }
+ src += i_stride;
+ }
+}
+static void predict_4x4_dc_top( uint8_t *src, int i_stride )
+{
+ int x,y;
+ int dc = ( src[0 - i_stride] + src[1 - i_stride] +
+ src[2 - i_stride] + src[3 - i_stride] + 2 ) >> 2;
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ src[x] = dc;
+ }
+ src += i_stride;
+ }
+}
+static void predict_4x4_dc( uint8_t *src, int i_stride )
+{
+ int x,y;
+ int dc = ( src[-1+0*i_stride] + src[-1+i_stride]+
+ src[-1+2*i_stride] + src[-1+3*i_stride] +
+ src[0 - i_stride] + src[1 - i_stride] +
+ src[2 - i_stride] + src[3 - i_stride] + 4 ) >> 3;
+
+ for( y = 0; y < 4; y++ )
+ {
+ for( x = 0; x < 4; x++ )
+ {
+ src[x] = dc;
+ }
+ src += i_stride;
+ }
+}
+static void predict_4x4_h( uint8_t *src, int i_stride )
+{
+ int i,j;
+
+ for( i = 0; i < 4; i++ )
+ {
+ uint8_t v;
+
+ v = src[-1];
+
+ for( j = 0; j < 4; j++ )
+ {
+ src[j] = v;
+ }
+ src += i_stride;
+ }
+}
+static void predict_4x4_v( uint8_t *src, int i_stride )
+{
+ int i,j;
+
+ for( i = 0; i < 4; i++ )
+ {
+ for( j = 0; j < 4; j++ )
+ {
+ src[i * i_stride +j] = src[j - i_stride];
+ }
+ }
+}
+
+#define PREDICT_4x4_LOAD_LEFT \
+ const int l0 = src[-1+0*i_stride]; \
+ const int l1 = src[-1+1*i_stride]; \
+ const int l2 = src[-1+2*i_stride]; \
+ const int l3 = src[-1+3*i_stride];
+
+#define PREDICT_4x4_LOAD_TOP \
+ const int t0 = src[0-1*i_stride]; \
+ const int t1 = src[1-1*i_stride]; \
+ const int t2 = src[2-1*i_stride]; \
+ const int t3 = src[3-1*i_stride];
+
+#define PREDICT_4x4_LOAD_TOP_RIGHT \
+ const int t4 = src[4-1*i_stride]; \
+ const int t5 = src[5-1*i_stride]; \
+ const int t6 = src[6-1*i_stride]; \
+ const int t7 = src[7-1*i_stride];
+
+
+static void predict_4x4_ddl( uint8_t *src, int i_stride )
+{
+ PREDICT_4x4_LOAD_TOP
+ PREDICT_4x4_LOAD_TOP_RIGHT
+
+ src[0*i_stride+0] = ( t0 + 2*t1+ t2 + 2 ) >> 2;
+
+ src[0*i_stride+1] =
+ src[1*i_stride+0] = ( t1 + 2*t2+ t3 + 2 ) >> 2;
+
+ src[0*i_stride+2] =
+ src[1*i_stride+1] =
+ src[2*i_stride+0] = ( t2 + 2*t3+ t4 + 2 ) >> 2;
+
+ src[0*i_stride+3] =
+ src[1*i_stride+2] =
+ src[2*i_stride+1] =
+ src[3*i_stride+0] = ( t3 + 2*t4+ t5 + 2 ) >> 2;
+
+ src[1*i_stride+3] =
+ src[2*i_stride+2] =
+ src[3*i_stride+1] = ( t4 + 2*t5+ t6 + 2 ) >> 2;
+
+ src[2*i_stride+3] =
+ src[3*i_stride+2] = ( t5 + 2*t6+ t7 + 2 ) >> 2;
+
+ src[3*i_stride+3] = ( t6 + 3 * t7 + 2 ) >> 2;
+}
+static void predict_4x4_ddr( uint8_t *src, int i_stride )
+{
+ const int lt = src[-1-i_stride];
+ PREDICT_4x4_LOAD_LEFT
+ PREDICT_4x4_LOAD_TOP
+
+ src[0*i_stride+0] =
+ src[1*i_stride+1] =
+ src[2*i_stride+2] =
+ src[3*i_stride+3] = ( t0 + 2*lt +l0 + 2 ) >> 2;
+
+ src[0*i_stride+1] =
+ src[1*i_stride+2] =
+ src[2*i_stride+3] = ( lt + 2 * t0 + t1 + 2 ) >> 2;
+
+ src[0*i_stride+2] =
+ src[1*i_stride+3] = ( t0 + 2 * t1 + t2 + 2 ) >> 2;
+
+ src[0*i_stride+3] = ( t1 + 2 * t2 + t3 + 2 ) >> 2;
+
+ src[1*i_stride+0] =
+ src[2*i_stride+1] =
+ src[3*i_stride+2] = ( lt + 2 * l0 + l1 + 2 ) >> 2;
+
+ src[2*i_stride+0] =
+ src[3*i_stride+1] = ( l0 + 2 * l1 + l2 + 2 ) >> 2;
+
+ src[3*i_stride+0] = ( l1 + 2 * l2 + l3 + 2 ) >> 2;
+}
+
+static void predict_4x4_vr( uint8_t *src, int i_stride )
+{
+ const int lt = src[-1-i_stride];
+ PREDICT_4x4_LOAD_LEFT
+ PREDICT_4x4_LOAD_TOP
+ /* produce warning as l3 is unused */
+
+ src[0*i_stride+0]=
+ src[2*i_stride+1]= ( lt + t0 + 1 ) >> 1;
+
+ src[0*i_stride+1]=
+ src[2*i_stride+2]= ( t0 + t1 + 1 ) >> 1;
+
+ src[0*i_stride+2]=
+ src[2*i_stride+3]= ( t1 + t2 + 1 ) >> 1;
+
+ src[0*i_stride+3]= ( t2 + t3 + 1 ) >> 1;
+
+ src[1*i_stride+0]=
+ src[3*i_stride+1]= ( l0 + 2 * lt + t0 + 2 ) >> 2;
+
+ src[1*i_stride+1]=
+ src[3*i_stride+2]= ( lt + 2 * t0 + t1 + 2 ) >> 2;
+
+ src[1*i_stride+2]=
+ src[3*i_stride+3]= ( t0 + 2 * t1 + t2 + 2) >> 2;
+
+ src[1*i_stride+3]= ( t1 + 2 * t2 + t3 + 2 ) >> 2;
+ src[2*i_stride+0]= ( lt + 2 * l0 + l1 + 2 ) >> 2;
+ src[3*i_stride+0]= ( l0 + 2 * l1 + l2 + 2 ) >> 2;
+}
+
+static void predict_4x4_hd( uint8_t *src, int i_stride )
+{
+ const int lt= src[-1-1*i_stride];
+ PREDICT_4x4_LOAD_LEFT
+ PREDICT_4x4_LOAD_TOP
+ /* produce warning as t3 is unused */
+
+ src[0*i_stride+0]=
+ src[1*i_stride+2]= ( lt + l0 + 1 ) >> 1;
+ src[0*i_stride+1]=
+ src[1*i_stride+3]= ( l0 + 2 * lt + t0 + 2 ) >> 2;
+ src[0*i_stride+2]= ( lt + 2 * t0 + t1 + 2 ) >> 2;
+ src[0*i_stride+3]= ( t0 + 2 * t1 + t2 + 2 ) >> 2;
+ src[1*i_stride+0]=
+ src[2*i_stride+2]= ( l0 + l1 + 1 ) >> 1;
+ src[1*i_stride+1]=
+ src[2*i_stride+3]= ( lt + 2 * l0 + l1 + 2 ) >> 2;
+ src[2*i_stride+0]=
+ src[3*i_stride+2]= ( l1 + l2+ 1 ) >> 1;
+ src[2*i_stride+1]=
+ src[3*i_stride+3]= ( l0 + 2 * l1 + l2 + 2 ) >> 2;
+ src[3*i_stride+0]= ( l2 + l3 + 1 ) >> 1;
+ src[3*i_stride+1]= ( l1 + 2 * l2 + l3 + 2 ) >> 2;
+}
+
+static void predict_4x4_vl( uint8_t *src, int i_stride )
+{
+ PREDICT_4x4_LOAD_TOP
+ PREDICT_4x4_LOAD_TOP_RIGHT
+ /* produce warning as t7 is unused */
+
+ src[0*i_stride+0]= ( t0 + t1 + 1 ) >> 1;
+ src[0*i_stride+1]=
+ src[2*i_stride+0]= ( t1 + t2 + 1 ) >> 1;
+ src[0*i_stride+2]=
+ src[2*i_stride+1]= ( t2 + t3 + 1 ) >> 1;
+ src[0*i_stride+3]=
+ src[2*i_stride+2]= ( t3 + t4+ 1 ) >> 1;
+ src[2*i_stride+3]= ( t4 + t5+ 1 ) >> 1;
+ src[1*i_stride+0]= ( t0 + 2 * t1 + t2 + 2 ) >> 2;
+ src[1*i_stride+1]=
+ src[3*i_stride+0]= ( t1 + 2 * t2 + t3 + 2 ) >> 2;
+ src[1*i_stride+2]=
+ src[3*i_stride+1]= ( t2 + 2 * t3 + t4 + 2 ) >> 2;
+ src[1*i_stride+3]=
+ src[3*i_stride+2]= ( t3 + 2 * t4 + t5 + 2 ) >> 2;
+ src[3*i_stride+3]= ( t4 + 2 * t5 + t6 + 2 ) >> 2;
+}
+
+static void predict_4x4_hu( uint8_t *src, int i_stride )
+{
+ PREDICT_4x4_LOAD_LEFT
+
+ src[0*i_stride+0]= ( l0 + l1 + 1 ) >> 1;
+ src[0*i_stride+1]= ( l0 + 2 * l1 + l2 + 2 ) >> 2;
+
+ src[0*i_stride+2]=
+ src[1*i_stride+0]= ( l1 + l2 + 1 ) >> 1;
+
+ src[0*i_stride+3]=
+ src[1*i_stride+1]= ( l1 + 2*l2 + l3 + 2 ) >> 2;
+
+ src[1*i_stride+2]=
+ src[2*i_stride+0]= ( l2 + l3 + 1 ) >> 1;
+
+ src[1*i_stride+3]=
+ src[2*i_stride+1]= ( l2 + 2 * l3 + l3 + 2 ) >> 2;
+
+ src[2*i_stride+3]=
+ src[3*i_stride+1]=
+ src[3*i_stride+0]=
+ src[2*i_stride+2]=
+ src[3*i_stride+2]=
+ src[3*i_stride+3]= l3;
+}
+
+/****************************************************************************
+ * Exported functions:
+ ****************************************************************************/
+void x264_predict_16x16_init( int cpu, x264_predict_t pf[7] )
+{
+ pf[I_PRED_16x16_V ] = predict_16x16_v;
+ pf[I_PRED_16x16_H ] = predict_16x16_h;
+ pf[I_PRED_16x16_DC] = predict_16x16_dc;
+ pf[I_PRED_16x16_P ] = predict_16x16_p;
+ pf[I_PRED_16x16_DC_LEFT]= predict_16x16_dc_left;
+ pf[I_PRED_16x16_DC_TOP ]= predict_16x16_dc_top;
+ pf[I_PRED_16x16_DC_128 ]= predict_16x16_dc_128;
+
+#ifdef HAVE_MMXEXT
+ if( cpu&X264_CPU_MMXEXT )
+ {
+ x264_predict_16x16_init_mmxext( pf );
+ }
+#endif
+}
+
+void x264_predict_8x8_init( int cpu, x264_predict_t pf[7] )
+{
+ pf[I_PRED_CHROMA_V ] = predict_8x8_v;
+ pf[I_PRED_CHROMA_H ] = predict_8x8_h;
+ pf[I_PRED_CHROMA_DC] = predict_8x8_dc;
+ pf[I_PRED_CHROMA_P ] = predict_8x8_p;
+ pf[I_PRED_CHROMA_DC_LEFT]= predict_8x8_dc_left;
+ pf[I_PRED_CHROMA_DC_TOP ]= predict_8x8_dc_top;
+ pf[I_PRED_CHROMA_DC_128 ]= predict_8x8_dc_128;
+
+#ifdef HAVE_MMXEXT
+ if( cpu&X264_CPU_MMXEXT )
+ {
+ x264_predict_8x8_init_mmxext( pf );
+ }
+#endif
+}
+
+void x264_predict_4x4_init( int cpu, x264_predict_t pf[12] )
+{
+ pf[I_PRED_4x4_V] = predict_4x4_v;
+ pf[I_PRED_4x4_H] = predict_4x4_h;
+ pf[I_PRED_4x4_DC] = predict_4x4_dc;
+ pf[I_PRED_4x4_DDL] = predict_4x4_ddl;
+ pf[I_PRED_4x4_DDR] = predict_4x4_ddr;
+ pf[I_PRED_4x4_VR] = predict_4x4_vr;
+ pf[I_PRED_4x4_HD] = predict_4x4_hd;
+ pf[I_PRED_4x4_VL] = predict_4x4_vl;
+ pf[I_PRED_4x4_HU] = predict_4x4_hu;
+ pf[I_PRED_4x4_DC_LEFT]= predict_4x4_dc_left;
+ pf[I_PRED_4x4_DC_TOP] = predict_4x4_dc_top;
+ pf[I_PRED_4x4_DC_128] = predict_4x4_dc_128;
+
+#ifdef HAVE_MMXEXT
+ if( cpu&X264_CPU_MMXEXT )
+ {
+ x264_predict_4x4_init_mmxext( pf );
+ }
+#endif
+}
+
--- /dev/null
+/*****************************************************************************
+ * predict.h: h264 encoder library
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: predict.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _PREDICT_H
+#define _PREDICT_H 1
+
+typedef void (*x264_predict_t)( uint8_t *src, int i_stride );
+
+enum intra_chroma_pred_e
+{
+ I_PRED_CHROMA_DC = 0,
+ I_PRED_CHROMA_H = 1,
+ I_PRED_CHROMA_V = 2,
+ I_PRED_CHROMA_P = 3,
+
+ I_PRED_CHROMA_DC_LEFT = 4,
+ I_PRED_CHROMA_DC_TOP = 5,
+ I_PRED_CHROMA_DC_128 = 6
+};
+static const int x264_mb_pred_mode8x8_fix[7] =
+{
+ I_PRED_CHROMA_DC, I_PRED_CHROMA_H, I_PRED_CHROMA_V, I_PRED_CHROMA_P,
+ I_PRED_CHROMA_DC, I_PRED_CHROMA_DC,I_PRED_CHROMA_DC
+};
+
+enum intra16x16_pred_e
+{
+ I_PRED_16x16_V = 0,
+ I_PRED_16x16_H = 1,
+ I_PRED_16x16_DC = 2,
+ I_PRED_16x16_P = 3,
+
+ I_PRED_16x16_DC_LEFT = 4,
+ I_PRED_16x16_DC_TOP = 5,
+ I_PRED_16x16_DC_128 = 6,
+};
+static const int x264_mb_pred_mode16x16_fix[7] =
+{
+ I_PRED_16x16_V, I_PRED_16x16_H, I_PRED_16x16_DC, I_PRED_16x16_P,
+ I_PRED_16x16_DC,I_PRED_16x16_DC,I_PRED_16x16_DC
+};
+
+enum intra4x4_pred_e
+{
+ I_PRED_4x4_V = 0,
+ I_PRED_4x4_H = 1,
+ I_PRED_4x4_DC = 2,
+ I_PRED_4x4_DDL= 3,
+ I_PRED_4x4_DDR= 4,
+ I_PRED_4x4_VR = 5,
+ I_PRED_4x4_HD = 6,
+ I_PRED_4x4_VL = 7,
+ I_PRED_4x4_HU = 8,
+
+ I_PRED_4x4_DC_LEFT = 9,
+ I_PRED_4x4_DC_TOP = 10,
+ I_PRED_4x4_DC_128 = 11,
+};
+static const int x264_mb_pred_mode4x4_fix[12] =
+{
+ I_PRED_4x4_V, I_PRED_4x4_H, I_PRED_4x4_DC,
+ I_PRED_4x4_DDL, I_PRED_4x4_DDR, I_PRED_4x4_VR,
+ I_PRED_4x4_HD, I_PRED_4x4_VL, I_PRED_4x4_HU,
+ I_PRED_4x4_DC, I_PRED_4x4_DC, I_PRED_4x4_DC
+};
+
+void x264_predict_16x16_init ( int cpu, x264_predict_t pf[7] );
+void x264_predict_8x8_init ( int cpu, x264_predict_t pf[7] );
+void x264_predict_4x4_init ( int cpu, x264_predict_t pf[12] );
+
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * set.h: h264 encoder
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: set.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+#ifndef _SET_H
+#define _SET_H 1
+
+enum profile_e
+{
+ PROFILE_BASELINE = 66,
+ PROFILE_MAIN = 77,
+ PROFILE_EXTENTED = 88
+};
+
+typedef struct
+{
+ int i_id;
+
+ int i_profile_idc;
+ int i_level_idc;
+
+ int b_constraint_set0;
+ int b_constraint_set1;
+ int b_constraint_set2;
+
+ int i_log2_max_frame_num;
+
+ int i_poc_type;
+ /* poc 0 */
+ int i_log2_max_poc_lsb;
+ /* poc 1 */
+ int b_delta_pic_order_always_zero;
+ int i_offset_for_non_ref_pic;
+ int i_offset_for_top_to_bottom_field;
+ int i_num_ref_frames_in_poc_cycle;
+ int i_offset_for_ref_frame[256];
+
+ int i_num_ref_frames;
+ int b_gaps_in_frame_num_value_allowed;
+ int i_mb_width;
+ int i_mb_height;
+ int b_frame_mbs_only;
+ int b_mb_adaptive_frame_field;
+ int b_direct8x8_inference;
+
+ int b_crop;
+ struct
+ {
+ int i_left;
+ int i_right;
+ int i_top;
+ int i_bottom;
+ } crop;
+
+ int b_vui;
+ struct
+ {
+ int b_aspect_ratio_info_present;
+ int i_sar_width;
+ int i_sar_height;
+
+ int b_timing_info_present;
+ int i_num_units_in_tick;
+ int i_time_scale;
+ int b_fixed_frame_rate;
+
+ /* FIXME to complete */
+ } vui;
+} x264_sps_t;
+
+typedef struct
+{
+ int i_id;
+ int i_sps_id;
+
+ int b_cabac;
+
+ int b_pic_order;
+ int i_num_slice_groups;
+
+ int i_slice_group_map_type;
+ /* i_slice_group_map_type == 0 */
+ int i_run_length[256]; /* FIXME */
+ /* i_slice_group_map_type == 2 */
+ int i_top_left[256]; /* FIXME */
+ int i_bottom_right[256]; /* FIXME */
+ /* i_slice_group_map_type == 3, 4, 5 */
+ int b_slice_group_change_direction;
+ int i_slice_group_change_rate;
+ /* i_slice_group_map_type == 6 */
+ int i_pic_size_in_map_units;
+ int i_slice_group_id[256]; /* FIXME */
+
+ int i_num_ref_idx_l0_active;
+ int i_num_ref_idx_l1_active;
+
+ int b_weighted_pred;
+ int b_weighted_bipred;
+
+ int i_pic_init_qp;
+ int i_pic_init_qs;
+
+ int i_chroma_qp_index_offset;
+
+ int b_deblocking_filter_control;
+ int b_constrained_intra_pred;
+ int b_redundant_pic_cnt;
+} x264_pps_t;
+
+#endif
--- /dev/null
+/*****************************************************************************
+ * vlc.h : vlc table
+ *****************************************************************************
+ * Copyright (C) 2003 Laurent Aimar
+ * $Id: vlc.h,v 1.1 2004/06/03 19:27:07 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.
+ *****************************************************************************/
+
+typedef struct
+{
+ int i_bits;
+ int i_size;
+} vlc_t;
+
+/* XXX: don't forget to change it if you change vlc_t */
+#define MKVLC( a, b ) { a, b }
+static const vlc_t x264_coeff_token[5][17*4] =
+{
+ /* table 0 */
+ {
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x5, 6 ), /* str=000101 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x7, 8 ), /* str=00000111 */
+ MKVLC( 0x4, 6 ), /* str=000100 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x7, 9 ), /* str=000000111 */
+ MKVLC( 0x6, 8 ), /* str=00000110 */
+ MKVLC( 0x5, 7 ), /* str=0000101 */
+ MKVLC( 0x3, 5 ), /* str=00011 */
+
+ MKVLC( 0x7, 10 ), /* str=0000000111 */
+ MKVLC( 0x6, 9 ), /* str=000000110 */
+ MKVLC( 0x5, 8 ), /* str=00000101 */
+ MKVLC( 0x3, 6 ), /* str=000011 */
+
+ MKVLC( 0x7, 11 ), /* str=00000000111 */
+ MKVLC( 0x6, 10 ), /* str=0000000110 */
+ MKVLC( 0x5, 9 ), /* str=000000101 */
+ MKVLC( 0x4, 7 ), /* str=0000100 */
+
+ MKVLC( 0xf, 13 ), /* str=0000000001111 */
+ MKVLC( 0x6, 11 ), /* str=00000000110 */
+ MKVLC( 0x5, 10 ), /* str=0000000101 */
+ MKVLC( 0x4, 8 ), /* str=00000100 */
+
+ MKVLC( 0xb, 13 ), /* str=0000000001011 */
+ MKVLC( 0xe, 13 ), /* str=0000000001110 */
+ MKVLC( 0x5, 11 ), /* str=00000000101 */
+ MKVLC( 0x4, 9 ), /* str=000000100 */
+
+ MKVLC( 0x8, 13 ), /* str=0000000001000 */
+ MKVLC( 0xa, 13 ), /* str=0000000001010 */
+ MKVLC( 0xd, 13 ), /* str=0000000001101 */
+ MKVLC( 0x4, 10 ), /* str=0000000100 */
+
+ MKVLC( 0xf, 14 ), /* str=00000000001111 */
+ MKVLC( 0xe, 14 ), /* str=00000000001110 */
+ MKVLC( 0x9, 13 ), /* str=0000000001001 */
+ MKVLC( 0x4, 11 ), /* str=00000000100 */
+
+ MKVLC( 0xb, 14 ), /* str=00000000001011 */
+ MKVLC( 0xa, 14 ), /* str=00000000001010 */
+ MKVLC( 0xd, 14 ), /* str=00000000001101 */
+ MKVLC( 0xc, 13 ), /* str=0000000001100 */
+
+ MKVLC( 0xf, 15 ), /* str=000000000001111 */
+ MKVLC( 0xe, 15 ), /* str=000000000001110 */
+ MKVLC( 0x9, 14 ), /* str=00000000001001 */
+ MKVLC( 0xc, 14 ), /* str=00000000001100 */
+
+ MKVLC( 0xb, 15 ), /* str=000000000001011 */
+ MKVLC( 0xa, 15 ), /* str=000000000001010 */
+ MKVLC( 0xd, 15 ), /* str=000000000001101 */
+ MKVLC( 0x8, 14 ), /* str=00000000001000 */
+
+ MKVLC( 0xf, 16 ), /* str=0000000000001111 */
+ MKVLC( 0x1, 15 ), /* str=000000000000001 */
+ MKVLC( 0x9, 15 ), /* str=000000000001001 */
+ MKVLC( 0xc, 15 ), /* str=000000000001100 */
+
+ MKVLC( 0xb, 16 ), /* str=0000000000001011 */
+ MKVLC( 0xe, 16 ), /* str=0000000000001110 */
+ MKVLC( 0xd, 16 ), /* str=0000000000001101 */
+ MKVLC( 0x8, 15 ), /* str=000000000001000 */
+
+ MKVLC( 0x7, 16 ), /* str=0000000000000111 */
+ MKVLC( 0xa, 16 ), /* str=0000000000001010 */
+ MKVLC( 0x9, 16 ), /* str=0000000000001001 */
+ MKVLC( 0xc, 16 ), /* str=0000000000001100 */
+
+ MKVLC( 0x4, 16 ), /* str=0000000000000100 */
+ MKVLC( 0x6, 16 ), /* str=0000000000000110 */
+ MKVLC( 0x5, 16 ), /* str=0000000000000101 */
+ MKVLC( 0x8, 16 ), /* str=0000000000001000 */
+ },
+
+ /* table 1 */
+ {
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0xb, 6 ), /* str=001011 */
+ MKVLC( 0x2, 2 ), /* str=10 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x7, 6 ), /* str=000111 */
+ MKVLC( 0x7, 5 ), /* str=00111 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x7, 7 ), /* str=0000111 */
+ MKVLC( 0xa, 6 ), /* str=001010 */
+ MKVLC( 0x9, 6 ), /* str=001001 */
+ MKVLC( 0x5, 4 ), /* str=0101 */
+
+ MKVLC( 0x7, 8 ), /* str=00000111 */
+ MKVLC( 0x6, 6 ), /* str=000110 */
+ MKVLC( 0x5, 6 ), /* str=000101 */
+ MKVLC( 0x4, 4 ), /* str=0100 */
+
+ MKVLC( 0x4, 8 ), /* str=00000100 */
+ MKVLC( 0x6, 7 ), /* str=0000110 */
+ MKVLC( 0x5, 7 ), /* str=0000101 */
+ MKVLC( 0x6, 5 ), /* str=00110 */
+
+ MKVLC( 0x7, 9 ), /* str=000000111 */
+ MKVLC( 0x6, 8 ), /* str=00000110 */
+ MKVLC( 0x5, 8 ), /* str=00000101 */
+ MKVLC( 0x8, 6 ), /* str=001000 */
+
+ MKVLC( 0xf, 11 ), /* str=00000001111 */
+ MKVLC( 0x6, 9 ), /* str=000000110 */
+ MKVLC( 0x5, 9 ), /* str=000000101 */
+ MKVLC( 0x4, 6 ), /* str=000100 */
+
+ MKVLC( 0xb, 11 ), /* str=00000001011 */
+ MKVLC( 0xe, 11 ), /* str=00000001110 */
+ MKVLC( 0xd, 11 ), /* str=00000001101 */
+ MKVLC( 0x4, 7 ), /* str=0000100 */
+
+ MKVLC( 0xf, 12 ), /* str=000000001111 */
+ MKVLC( 0xa, 11 ), /* str=00000001010 */
+ MKVLC( 0x9, 11 ), /* str=00000001001 */
+ MKVLC( 0x4, 9 ), /* str=000000100 */
+
+ MKVLC( 0xb, 12 ), /* str=000000001011 */
+ MKVLC( 0xe, 12 ), /* str=000000001110 */
+ MKVLC( 0xd, 12 ), /* str=000000001101 */
+ MKVLC( 0xc, 11 ), /* str=00000001100 */
+
+ MKVLC( 0x8, 12 ), /* str=000000001000 */
+ MKVLC( 0xa, 12 ), /* str=000000001010 */
+ MKVLC( 0x9, 12 ), /* str=000000001001 */
+ MKVLC( 0x8, 11 ), /* str=00000001000 */
+
+ MKVLC( 0xf, 13 ), /* str=0000000001111 */
+ MKVLC( 0xe, 13 ), /* str=0000000001110 */
+ MKVLC( 0xd, 13 ), /* str=0000000001101 */
+ MKVLC( 0xc, 12 ), /* str=000000001100 */
+
+ MKVLC( 0xb, 13 ), /* str=0000000001011 */
+ MKVLC( 0xa, 13 ), /* str=0000000001010 */
+ MKVLC( 0x9, 13 ), /* str=0000000001001 */
+ MKVLC( 0xc, 13 ), /* str=0000000001100 */
+
+ MKVLC( 0x7, 13 ), /* str=0000000000111 */
+ MKVLC( 0xb, 14 ), /* str=00000000001011 */
+ MKVLC( 0x6, 13 ), /* str=0000000000110 */
+ MKVLC( 0x8, 13 ), /* str=0000000001000 */
+
+ MKVLC( 0x9, 14 ), /* str=00000000001001 */
+ MKVLC( 0x8, 14 ), /* str=00000000001000 */
+ MKVLC( 0xa, 14 ), /* str=00000000001010 */
+ MKVLC( 0x1, 13 ), /* str=0000000000001 */
+
+ MKVLC( 0x7, 14 ), /* str=00000000000111 */
+ MKVLC( 0x6, 14 ), /* str=00000000000110 */
+ MKVLC( 0x5, 14 ), /* str=00000000000101 */
+ MKVLC( 0x4, 14 ), /* str=00000000000100 */
+ },
+ /* table 2 */
+ {
+ MKVLC( 0xf, 4 ), /* str=1111 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0xf, 6 ), /* str=001111 */
+ MKVLC( 0xe, 4 ), /* str=1110 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0xb, 6 ), /* str=001011 */
+ MKVLC( 0xf, 5 ), /* str=01111 */
+ MKVLC( 0xd, 4 ), /* str=1101 */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x8, 6 ), /* str=001000 */
+ MKVLC( 0xc, 5 ), /* str=01100 */
+ MKVLC( 0xe, 5 ), /* str=01110 */
+ MKVLC( 0xc, 4 ), /* str=1100 */
+
+ MKVLC( 0xf, 7 ), /* str=0001111 */
+ MKVLC( 0xa, 5 ), /* str=01010 */
+ MKVLC( 0xb, 5 ), /* str=01011 */
+ MKVLC( 0xb, 4 ), /* str=1011 */
+
+ MKVLC( 0xb, 7 ), /* str=0001011 */
+ MKVLC( 0x8, 5 ), /* str=01000 */
+ MKVLC( 0x9, 5 ), /* str=01001 */
+ MKVLC( 0xa, 4 ), /* str=1010 */
+
+ MKVLC( 0x9, 7 ), /* str=0001001 */
+ MKVLC( 0xe, 6 ), /* str=001110 */
+ MKVLC( 0xd, 6 ), /* str=001101 */
+ MKVLC( 0x9, 4 ), /* str=1001 */
+
+ MKVLC( 0x8, 7 ), /* str=0001000 */
+ MKVLC( 0xa, 6 ), /* str=001010 */
+ MKVLC( 0x9, 6 ), /* str=001001 */
+ MKVLC( 0x8, 4 ), /* str=1000 */
+
+ MKVLC( 0xf, 8 ), /* str=00001111 */
+ MKVLC( 0xe, 7 ), /* str=0001110 */
+ MKVLC( 0xd, 7 ), /* str=0001101 */
+ MKVLC( 0xd, 5 ), /* str=01101 */
+
+ MKVLC( 0xb, 8 ), /* str=00001011 */
+ MKVLC( 0xe, 8 ), /* str=00001110 */
+ MKVLC( 0xa, 7 ), /* str=0001010 */
+ MKVLC( 0xc, 6 ), /* str=001100 */
+
+ MKVLC( 0xf, 9 ), /* str=000001111 */
+ MKVLC( 0xa, 8 ), /* str=00001010 */
+ MKVLC( 0xd, 8 ), /* str=00001101 */
+ MKVLC( 0xc, 7 ), /* str=0001100 */
+
+ MKVLC( 0xb, 9 ), /* str=000001011 */
+ MKVLC( 0xe, 9 ), /* str=000001110 */
+ MKVLC( 0x9, 8 ), /* str=00001001 */
+ MKVLC( 0xc, 8 ), /* str=00001100 */
+
+ MKVLC( 0x8, 9 ), /* str=000001000 */
+ MKVLC( 0xa, 9 ), /* str=000001010 */
+ MKVLC( 0xd, 9 ), /* str=000001101 */
+ MKVLC( 0x8, 8 ), /* str=00001000 */
+
+ MKVLC( 0xd, 10 ), /* str=0000001101 */
+ MKVLC( 0x7, 9 ), /* str=000000111 */
+ MKVLC( 0x9, 9 ), /* str=000001001 */
+ MKVLC( 0xc, 9 ), /* str=000001100 */
+
+ MKVLC( 0x9, 10 ), /* str=0000001001 */
+ MKVLC( 0xc, 10 ), /* str=0000001100 */
+ MKVLC( 0xb, 10 ), /* str=0000001011 */
+ MKVLC( 0xa, 10 ), /* str=0000001010 */
+
+ MKVLC( 0x5, 10 ), /* str=0000000101 */
+ MKVLC( 0x8, 10 ), /* str=0000001000 */
+ MKVLC( 0x7, 10 ), /* str=0000000111 */
+ MKVLC( 0x6, 10 ), /* str=0000000110 */
+
+ MKVLC( 0x1, 10 ), /* str=0000000001 */
+ MKVLC( 0x4, 10 ), /* str=0000000100 */
+ MKVLC( 0x3, 10 ), /* str=0000000011 */
+ MKVLC( 0x2, 10 ), /* str=0000000010 */
+ },
+
+ /* table 3 */
+ {
+ MKVLC( 0x3, 6 ), /* str=000011 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 6 ), /* str=000000 */
+ MKVLC( 0x1, 6 ), /* str=000001 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x4, 6 ), /* str=000100 */
+ MKVLC( 0x5, 6 ), /* str=000101 */
+ MKVLC( 0x6, 6 ), /* str=000110 */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x8, 6 ), /* str=001000 */
+ MKVLC( 0x9, 6 ), /* str=001001 */
+ MKVLC( 0xa, 6 ), /* str=001010 */
+ MKVLC( 0xb, 6 ), /* str=001011 */
+
+ MKVLC( 0xc, 6 ), /* str=001100 */
+ MKVLC( 0xd, 6 ), /* str=001101 */
+ MKVLC( 0xe, 6 ), /* str=001110 */
+ MKVLC( 0xf, 6 ), /* str=001111 */
+
+ MKVLC( 0x10, 6 ), /* str=010000 */
+ MKVLC( 0x11, 6 ), /* str=010001 */
+ MKVLC( 0x12, 6 ), /* str=010010 */
+ MKVLC( 0x13, 6 ), /* str=010011 */
+
+ MKVLC( 0x14, 6 ), /* str=010100 */
+ MKVLC( 0x15, 6 ), /* str=010101 */
+ MKVLC( 0x16, 6 ), /* str=010110 */
+ MKVLC( 0x17, 6 ), /* str=010111 */
+
+ MKVLC( 0x18, 6 ), /* str=011000 */
+ MKVLC( 0x19, 6 ), /* str=011001 */
+ MKVLC( 0x1a, 6 ), /* str=011010 */
+ MKVLC( 0x1b, 6 ), /* str=011011 */
+
+ MKVLC( 0x1c, 6 ), /* str=011100 */
+ MKVLC( 0x1d, 6 ), /* str=011101 */
+ MKVLC( 0x1e, 6 ), /* str=011110 */
+ MKVLC( 0x1f, 6 ), /* str=011111 */
+
+ MKVLC( 0x20, 6 ), /* str=100000 */
+ MKVLC( 0x21, 6 ), /* str=100001 */
+ MKVLC( 0x22, 6 ), /* str=100010 */
+ MKVLC( 0x23, 6 ), /* str=100011 */
+
+ MKVLC( 0x24, 6 ), /* str=100100 */
+ MKVLC( 0x25, 6 ), /* str=100101 */
+ MKVLC( 0x26, 6 ), /* str=100110 */
+ MKVLC( 0x27, 6 ), /* str=100111 */
+
+ MKVLC( 0x28, 6 ), /* str=101000 */
+ MKVLC( 0x29, 6 ), /* str=101001 */
+ MKVLC( 0x2a, 6 ), /* str=101010 */
+ MKVLC( 0x2b, 6 ), /* str=101011 */
+
+ MKVLC( 0x2c, 6 ), /* str=101100 */
+ MKVLC( 0x2d, 6 ), /* str=101101 */
+ MKVLC( 0x2e, 6 ), /* str=101110 */
+ MKVLC( 0x2f, 6 ), /* str=101111 */
+
+ MKVLC( 0x30, 6 ), /* str=110000 */
+ MKVLC( 0x31, 6 ), /* str=110001 */
+ MKVLC( 0x32, 6 ), /* str=110010 */
+ MKVLC( 0x33, 6 ), /* str=110011 */
+
+ MKVLC( 0x34, 6 ), /* str=110100 */
+ MKVLC( 0x35, 6 ), /* str=110101 */
+ MKVLC( 0x36, 6 ), /* str=110110 */
+ MKVLC( 0x37, 6 ), /* str=110111 */
+
+ MKVLC( 0x38, 6 ), /* str=111000 */
+ MKVLC( 0x39, 6 ), /* str=111001 */
+ MKVLC( 0x3a, 6 ), /* str=111010 */
+ MKVLC( 0x3b, 6 ), /* str=111011 */
+
+ MKVLC( 0x3c, 6 ), /* str=111100 */
+ MKVLC( 0x3d, 6 ), /* str=111101 */
+ MKVLC( 0x3e, 6 ), /* str=111110 */
+ MKVLC( 0x3f, 6 ), /* str=111111 */
+ },
+
+ /* table 4 */
+ {
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x7, 6 ), /* str=000111 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x4, 6 ), /* str=000100 */
+ MKVLC( 0x6, 6 ), /* str=000110 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x3, 6 ), /* str=000011 */
+ MKVLC( 0x3, 7 ), /* str=0000011 */
+ MKVLC( 0x2, 7 ), /* str=0000010 */
+ MKVLC( 0x5, 6 ), /* str=000101 */
+
+ MKVLC( 0x2, 6 ), /* str=000010 */
+ MKVLC( 0x3, 8 ), /* str=00000011 */
+ MKVLC( 0x2, 8 ), /* str=00000010 */
+ MKVLC( 0x0, 7 ), /* str=0000000 */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ }
+};
+
+static const vlc_t x264_level_prefix[16] =
+{
+ MKVLC( 0x01, 1 ),
+ MKVLC( 0x01, 2 ),
+ MKVLC( 0x01, 3 ),
+ MKVLC( 0x01, 4 ),
+ MKVLC( 0x01, 5 ),
+ MKVLC( 0x01, 6 ),
+ MKVLC( 0x01, 7 ),
+ MKVLC( 0x01, 8 ),
+ MKVLC( 0x01, 9 ),
+ MKVLC( 0x01, 10 ),
+ MKVLC( 0x01, 11 ),
+ MKVLC( 0x01, 12 ),
+ MKVLC( 0x01, 13 ),
+ MKVLC( 0x01, 14 ),
+ MKVLC( 0x01, 15 ),
+ MKVLC( 0x01, 16 )
+};
+
+/* [i_total_coeff-1][i_total_zeros] */
+static const vlc_t x264_total_zeros[15][16] =
+{
+ { /* i_total 1 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x2, 3 ), /* str=010 */
+ MKVLC( 0x3, 4 ), /* str=0011 */
+ MKVLC( 0x2, 4 ), /* str=0010 */
+ MKVLC( 0x3, 5 ), /* str=00011 */
+ MKVLC( 0x2, 5 ), /* str=00010 */
+ MKVLC( 0x3, 6 ), /* str=000011 */
+ MKVLC( 0x2, 6 ), /* str=000010 */
+ MKVLC( 0x3, 7 ), /* str=0000011 */
+ MKVLC( 0x2, 7 ), /* str=0000010 */
+ MKVLC( 0x3, 8 ), /* str=00000011 */
+ MKVLC( 0x2, 8 ), /* str=00000010 */
+ MKVLC( 0x3, 9 ), /* str=000000011 */
+ MKVLC( 0x2, 9 ), /* str=000000010 */
+ MKVLC( 0x1, 9 ), /* str=000000001 */
+ },
+ { /* i_total 2 */
+ MKVLC( 0x7, 3 ), /* str=111 */
+ MKVLC( 0x6, 3 ), /* str=110 */
+ MKVLC( 0x5, 3 ), /* str=101 */
+ MKVLC( 0x4, 3 ), /* str=100 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x5, 4 ), /* str=0101 */
+ MKVLC( 0x4, 4 ), /* str=0100 */
+ MKVLC( 0x3, 4 ), /* str=0011 */
+ MKVLC( 0x2, 4 ), /* str=0010 */
+ MKVLC( 0x3, 5 ), /* str=00011 */
+ MKVLC( 0x2, 5 ), /* str=00010 */
+ MKVLC( 0x3, 6 ), /* str=000011 */
+ MKVLC( 0x2, 6 ), /* str=000010 */
+ MKVLC( 0x1, 6 ), /* str=000001 */
+ MKVLC( 0x0, 6 ), /* str=000000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 3 */
+ MKVLC( 0x5, 4 ), /* str=0101 */
+ MKVLC( 0x7, 3 ), /* str=111 */
+ MKVLC( 0x6, 3 ), /* str=110 */
+ MKVLC( 0x5, 3 ), /* str=101 */
+ MKVLC( 0x4, 4 ), /* str=0100 */
+ MKVLC( 0x3, 4 ), /* str=0011 */
+ MKVLC( 0x4, 3 ), /* str=100 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x2, 4 ), /* str=0010 */
+ MKVLC( 0x3, 5 ), /* str=00011 */
+ MKVLC( 0x2, 5 ), /* str=00010 */
+ MKVLC( 0x1, 6 ), /* str=000001 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x0, 6 ), /* str=000000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 4 */
+ MKVLC( 0x3, 5 ), /* str=00011 */
+ MKVLC( 0x7, 3 ), /* str=111 */
+ MKVLC( 0x5, 4 ), /* str=0101 */
+ MKVLC( 0x4, 4 ), /* str=0100 */
+ MKVLC( 0x6, 3 ), /* str=110 */
+ MKVLC( 0x5, 3 ), /* str=101 */
+ MKVLC( 0x4, 3 ), /* str=100 */
+ MKVLC( 0x3, 4 ), /* str=0011 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x2, 4 ), /* str=0010 */
+ MKVLC( 0x2, 5 ), /* str=00010 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x0, 5 ), /* str=00000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 5 */
+ MKVLC( 0x5, 4 ), /* str=0101 */
+ MKVLC( 0x4, 4 ), /* str=0100 */
+ MKVLC( 0x3, 4 ), /* str=0011 */
+ MKVLC( 0x7, 3 ), /* str=111 */
+ MKVLC( 0x6, 3 ), /* str=110 */
+ MKVLC( 0x5, 3 ), /* str=101 */
+ MKVLC( 0x4, 3 ), /* str=100 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x2, 4 ), /* str=0010 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x0, 5 ), /* str=00000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 6 */
+ MKVLC( 0x1, 6 ), /* str=000001 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x7, 3 ), /* str=111 */
+ MKVLC( 0x6, 3 ), /* str=110 */
+ MKVLC( 0x5, 3 ), /* str=101 */
+ MKVLC( 0x4, 3 ), /* str=100 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x2, 3 ), /* str=010 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x0, 6 ), /* str=000000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 7 */
+ MKVLC( 0x1, 6 ), /* str=000001 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x5, 3 ), /* str=101 */
+ MKVLC( 0x4, 3 ), /* str=100 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x2, 3 ), /* str=010 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x0, 6 ), /* str=000000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 8 */
+ MKVLC( 0x1, 6 ), /* str=000001 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x2, 2 ), /* str=10 */
+ MKVLC( 0x2, 3 ), /* str=010 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x0, 6 ), /* str=000000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 9 */
+ MKVLC( 0x1, 6 ), /* str=000001 */
+ MKVLC( 0x0, 6 ), /* str=000000 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x2, 2 ), /* str=10 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 10 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x0, 5 ), /* str=00000 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x2, 2 ), /* str=10 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 11 */
+ MKVLC( 0x0, 4 ), /* str=0000 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x2, 3 ), /* str=010 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 12 */
+ MKVLC( 0x0, 4 ), /* str=0000 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 13 */
+ MKVLC( 0x0, 3 ), /* str=000 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 14 */
+ MKVLC( 0x0, 2 ), /* str=00 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_total 15 */
+ MKVLC( 0x0, 1 ), /* str=0 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+};
+
+/* [i_total_coeff-1][i_total_zeros] */
+static const vlc_t x264_total_zeros_dc[3][4] =
+{
+ {
+ MKVLC( 0x01, 1 ), /* 1 */
+ MKVLC( 0x01, 2 ), /* 01 */
+ MKVLC( 0x01, 3 ), /* 001*/
+ MKVLC( 0x00, 3 ) /* 000*/
+ },
+ {
+ MKVLC( 0x01, 1 ), /* 1 */
+ MKVLC( 0x01, 2 ), /* 01 */
+ MKVLC( 0x00, 2 ), /* 00 */
+ MKVLC( 0x00, 0 ) /* */
+ },
+ {
+ MKVLC( 0x01, 1 ), /* 1 */
+ MKVLC( 0x00, 1 ), /* 0 */
+ MKVLC( 0x00, 0 ), /* */
+ MKVLC( 0x00, 0 ) /* */
+ }
+};
+
+/* x264_run_before[__MIN( i_zero_left -1, 6 )][run_before] */
+static const vlc_t x264_run_before[7][15] =
+{
+ { /* i_zero_left 1 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x0, 1 ), /* str=0 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_zero_left 2 */
+ MKVLC( 0x1, 1 ), /* str=1 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x0, 2 ), /* str=00 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_zero_left 3 */
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x2, 2 ), /* str=10 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x0, 2 ), /* str=00 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_zero_left 4 */
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x2, 2 ), /* str=10 */
+ MKVLC( 0x1, 2 ), /* str=01 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x0, 3 ), /* str=000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_zero_left 5 */
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x2, 2 ), /* str=10 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x2, 3 ), /* str=010 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x0, 3 ), /* str=000 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_zero_left 6 */
+ MKVLC( 0x3, 2 ), /* str=11 */
+ MKVLC( 0x0, 3 ), /* str=000 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x2, 3 ), /* str=010 */
+ MKVLC( 0x5, 3 ), /* str=101 */
+ MKVLC( 0x4, 3 ), /* str=100 */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ MKVLC( 0x0, 0 ), /* str= */
+ },
+ { /* i_zero_left 7 */
+ MKVLC( 0x7, 3 ), /* str=111 */
+ MKVLC( 0x6, 3 ), /* str=110 */
+ MKVLC( 0x5, 3 ), /* str=101 */
+ MKVLC( 0x4, 3 ), /* str=100 */
+ MKVLC( 0x3, 3 ), /* str=011 */
+ MKVLC( 0x2, 3 ), /* str=010 */
+ MKVLC( 0x1, 3 ), /* str=001 */
+ MKVLC( 0x1, 4 ), /* str=0001 */
+ MKVLC( 0x1, 5 ), /* str=00001 */
+ MKVLC( 0x1, 6 ), /* str=000001 */
+ MKVLC( 0x1, 7 ), /* str=0000001 */
+ MKVLC( 0x1, 8 ), /* str=00000001 */
+ MKVLC( 0x1, 9 ), /* str=000000001 */
+ MKVLC( 0x1, 10 ), /* str=0000000001 */
+ MKVLC( 0x1, 11 ), /* str=00000000001 */
+ },
+};
+++ /dev/null
-/*****************************************************************************
- * bs.h :
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: bs.h,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifdef _BS_H
-#warning FIXME Multiple inclusion of bs.h
-#else
-#define _BS_H
-
-typedef struct bs_s
-{
- uint8_t *p_start;
- uint8_t *p;
- uint8_t *p_end;
-
- int i_left; /* i_count number of available bits */
-} bs_t;
-
-static inline void bs_init( bs_t *s, void *p_data, int i_data )
-{
- s->p_start = p_data;
- s->p = p_data;
- s->p_end = s->p + i_data;
- s->i_left = 8;
-}
-static inline int bs_pos( bs_t *s )
-{
- return( 8 * ( s->p - s->p_start ) + 8 - s->i_left );
-}
-static inline int bs_eof( bs_t *s )
-{
- return( s->p >= s->p_end ? 1: 0 );
-}
-static inline uint32_t bs_read( bs_t *s, int i_count )
-{
- static uint32_t i_mask[33] ={0x00,
- 0x01, 0x03, 0x07, 0x0f,
- 0x1f, 0x3f, 0x7f, 0xff,
- 0x1ff, 0x3ff, 0x7ff, 0xfff,
- 0x1fff, 0x3fff, 0x7fff, 0xffff,
- 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff,
- 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff,
- 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff,
- 0x1fffffff,0x3fffffff,0x7fffffff,0xffffffff};
- int i_shr;
- uint32_t i_result = 0;
-
- while( i_count > 0 )
- {
- if( s->p >= s->p_end )
- {
- break;
- }
-
- if( ( i_shr = s->i_left - i_count ) >= 0 )
- {
- /* more in the buffer than requested */
- i_result |= ( *s->p >> i_shr )&i_mask[i_count];
- s->i_left -= i_count;
- if( s->i_left == 0 )
- {
- s->p++;
- s->i_left = 8;
- }
- return( i_result );
- }
- else
- {
- /* less in the buffer than requested */
- i_result |= (*s->p&i_mask[s->i_left]) << -i_shr;
- i_count -= s->i_left;
- s->p++;
- s->i_left = 8;
- }
- }
-
- return( i_result );
-}
-
-#if 0
-/* Only > i386 */
-static uint32_t bswap32( uint32_t x )
-{
- asm( "bswap %0": "=r" (x):"0" (x));
- return x;
-}
-/* work only for i_count <= 32 - 7 */
-static inline uint32_t bs_read( bs_t *s, int i_count )
-{
- if( s->p < s->p_end && i_count > 0 )
- {
-#if 0
- uint32_t i_cache = ((s->p[0] << 24)+(s->p[1] << 16)+(s->p[2] << 8)+s->p[3]) << (8-s->i_left);
-#else
- uint32_t i_cache = bswap32( *((uint32_t*)s->p) ) << (8-s->i_left);
-#endif
- uint32_t i_ret = i_cache >> ( 32 - i_count);
-
- s->i_left -= i_count;
-#if 0
- if( s->i_left <= 0 )
- {
- int i_skip = (8-s->i_left) >> 3;
-
- s->p += i_skip;
-
- s->i_left += i_skip << 3;
- }
-#else
- while( s->i_left <= 0 )
- {
- s->p++;
- s->i_left += 8;
- }
-#endif
- return i_ret;
- }
- return 0;
-}
-
-#endif
-static inline uint32_t bs_read1( bs_t *s )
-{
-
- if( s->p < s->p_end )
- {
- unsigned int i_result;
-
- s->i_left--;
- i_result = ( *s->p >> s->i_left )&0x01;
- if( s->i_left == 0 )
- {
- s->p++;
- s->i_left = 8;
- }
- return i_result;
- }
-
- return 0;
-}
-static inline uint32_t bs_show( bs_t *s, int i_count )
-{
-#if 0
- bs_t s_tmp = *s;
- return bs_read( &s_tmp, i_count );
-#else
- if( s->p < s->p_end && i_count > 0 )
- {
- uint32_t i_cache = ((s->p[0] << 24)+(s->p[1] << 16)+(s->p[2] << 8)+s->p[3]) << (8-s->i_left);
- return( i_cache >> ( 32 - i_count) );
- }
- return 0;
-#endif
-}
-
-/* TODO optimize */
-static inline void bs_skip( bs_t *s, int i_count )
-{
- s->i_left -= i_count;
-
- while( s->i_left <= 0 )
- {
- s->p++;
- s->i_left += 8;
- }
-}
-
-
-static inline int bs_read_ue( bs_t *s )
-{
- int i = 0;
-
- while( bs_read1( s ) == 0 && s->p < s->p_end && i < 32 )
- {
- i++;
- }
- return( ( 1 << i) - 1 + bs_read( s, i ) );
-}
-static inline int bs_read_se( bs_t *s )
-{
- int val = bs_read_ue( s );
-
- return val&0x01 ? (val+1)/2 : -(val/2);
-}
-
-static inline int bs_read_te( bs_t *s, int x )
-{
- if( x == 1 )
- {
- return 1 - bs_read1( s );
- }
- else if( x > 1 )
- {
- return bs_read_ue( s );
- }
- return 0;
-}
-
-/* TODO optimize (write x bits at once) */
-static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits )
-{
- while( i_count > 0 )
- {
- if( s->p >= s->p_end )
- {
- break;
- }
-
- i_count--;
-
- if( ( i_bits >> i_count )&0x01 )
- {
- *s->p |= 1 << ( s->i_left - 1 );
- }
- else
- {
- *s->p &= ~( 1 << ( s->i_left - 1 ) );
- }
- s->i_left--;
- if( s->i_left == 0 )
- {
- s->p++;
- s->i_left = 8;
- }
- }
-}
-
-static inline void bs_write1( bs_t *s, uint32_t i_bits )
-{
- if( s->p < s->p_end )
- {
- s->i_left--;
-
- if( i_bits&0x01 )
- {
- *s->p |= 1 << s->i_left;
- }
- else
- {
- *s->p &= ~( 1 << s->i_left );
- }
- if( s->i_left == 0 )
- {
- s->p++;
- s->i_left = 8;
- }
- }
-}
-
-static inline void bs_align( bs_t *s )
-{
- if( s->i_left != 8 )
- {
- s->i_left = 8;
- s->p++;
- }
-}
-static inline void bs_align_0( bs_t *s )
-{
- if( s->i_left != 8 )
- {
- bs_write( s, s->i_left, 0 );
- }
-}
-static inline void bs_align_1( bs_t *s )
-{
- if( s->i_left != 8 )
- {
- bs_write( s, s->i_left, 1 );
- }
-}
-
-
-
-/* golomb functions */
-
-static inline void bs_write_ue( bs_t *s, unsigned int val )
-{
- int i_size = 0;
- static const int i_size0_255[256] =
- {
- 1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
- 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
- };
-
- if( val == 0 )
- {
- bs_write( s, 1, 1 );
- }
- else
- {
- unsigned int tmp = ++val;
-
- if( tmp >= 0x00010000 )
- {
- i_size += 16;
- tmp >>= 16;
- }
- if( tmp >= 0x100 )
- {
- i_size += 8;
- tmp >>= 8;
- }
- i_size += i_size0_255[tmp];
-
- bs_write( s, 2 * i_size - 1, val );
- }
-}
-
-static inline void bs_write_se( bs_t *s, int val )
-{
- bs_write_ue( s, val <= 0 ? -val * 2 : val * 2 - 1);
-}
-
-static inline void bs_write_te( bs_t *s, int x, int val )
-{
- if( x == 1 )
- {
- bs_write( s, 1, ~val );
- }
- else if( x > 1 )
- {
- bs_write_ue( s, val );
- }
-}
-
-static inline void bs_rbsp_trailing( bs_t *s )
-{
- bs_write( s, 1, 1 );
- if( s->i_left != 8 )
- {
- bs_write( s, s->i_left, 0x00 );
- }
-}
-
-static inline int bs_size_ue( unsigned int val )
-{
- static const int i_size0_254[255] =
- {
- 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
- 11,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
- 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
- 13,13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
- 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
- 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
- 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
- 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
- 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15
- };
-
- if( val < 255 )
- {
- return i_size0_254[val];
- }
- else
- {
- int i_size = 0;
-
- val++;
-
- if( val >= 0x10000 )
- {
- i_size += 32;
- val = (val >> 16) - 1;
- }
- if( val >= 0x100 )
- {
- i_size += 16;
- val = (val >> 8) - 1;
- }
- return i_size0_254[val] + i_size;
- }
-}
-
-static inline int bs_size_se( int val )
-{
- return bs_size_ue( val <= 0 ? -val * 2 : val * 2 - 1);
-}
-
-static inline int bs_size_te( int x, int val )
-{
- if( x == 1 )
- {
- return 1;
- }
- else if( x > 1 )
- {
- return bs_size_ue( val );
- }
- return 0;
-}
-
-
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * cabac.c: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: cabac.c,v 1.1 2004/06/03 19:27:06 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 <string.h>
-#include <stdio.h>
-
-#include "common.h"
-
-//#define TRACE 1
-
-/* Debugging purpose ONLY !!!! */
-#ifdef TRACE
-static int binCount = 0;
-#endif
-
-
-static const int x264_cabac_context_init_I[399][2] =
-{
- /* 0 - 10 */
- { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
- { 2, 54 }, { 3, 74 }, { -28,127 }, { -23, 104 },
- { -6, 53 }, { -1, 54 }, { 7, 51 },
-
- /* 11 - 23 unsused for I */
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 },
-
- /* 24- 39 */
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
-
- /* 40 - 53 */
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 },
-
- /* 54 - 59 */
- { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
- { 0, 0 }, { 0, 0 },
-
- /* 60 - 69 */
- { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
- { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
- { 13, 41 }, { 3, 62 },
-
- /* 70 -> 87 */
- { 0, 11 }, { 1, 55 }, { 0, 69 }, { -17, 127 },
- { -13, 102 },{ 0, 82 }, { -7, 74 }, { -21, 107 },
- { -27, 127 },{ -31, 127 },{ -24, 127 }, { -18, 95 },
- { -27, 127 },{ -21, 114 },{ -30, 127 }, { -17, 123 },
- { -12, 115 },{ -16, 122 },
-
- /* 88 -> 104 */
- { -11, 115 },{ -12, 63 }, { -2, 68 }, { -15, 84 },
- { -13, 104 },{ -3, 70 }, { -8, 93 }, { -10, 90 },
- { -30, 127 },{ -1, 74 }, { -6, 97 }, { -7, 91 },
- { -20, 127 },{ -4, 56 }, { -5, 82 }, { -7, 76 },
- { -22, 125 },
-
- /* 105 -> 135 */
- { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 },
- { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 },
- { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 },
- { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 },
- { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 },
- { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 },
- { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 },
- { 14, 62 }, { -13, 108 },{ -15, 100 },
-
- /* 136 -> 165 */
- { -13, 101 },{ -13, 91 }, { -12, 94 }, { -10, 88 },
- { -16, 84 }, { -10, 86 }, { -7, 83 }, { -13, 87 },
- { -19, 94 }, { 1, 70 }, { 0, 72 }, { -5, 74 },
- { 18, 59 }, { -8, 102 }, { -15, 100 }, { 0, 95 },
- { -4, 75 }, { 2, 72 }, { -11, 75 }, { -3, 71 },
- { 15, 46 }, { -13, 69 }, { 0, 62 }, { 0, 65 },
- { 21, 37 }, { -15, 72 }, { 9, 57 }, { 16, 54 },
- { 0, 62 }, { 12, 72 },
-
- /* 166 -> 196 */
- { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 },
- { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 },
- { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 },
- { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 },
- { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 },
- { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 },
- { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 },
- { 0, 89 }, { 26, -19 }, { 22, -17 },
-
- /* 197 -> 226 */
- { 26, -17 }, { 30, -25 }, { 28, -20 }, { 33, -23 },
- { 37, -27 }, { 33, -23 }, { 40, -28 }, { 38, -17 },
- { 33, -11 }, { 40, -15 }, { 41, -6 }, { 38, 1 },
- { 41, 17 }, { 30, -6 }, { 27, 3 }, { 26, 22 },
- { 37, -16 }, { 35, -4 }, { 38, -8 }, { 38, -3 },
- { 37, 3 }, { 38, 5 }, { 42, 0 }, { 35, 16 },
- { 39, 22 }, { 14, 48 }, { 27, 37 }, { 21, 60 },
- { 12, 68 }, { 2, 97 },
-
- /* 227 -> 251 */
- { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 },
- { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 },
- { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 },
- { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 },
- { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 },
- { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 },
- { -4, 65 },
-
- /* 252 -> 275 */
- { -12, 73 }, { -8, 76 }, { -7, 80 }, { -9, 88 },
- { -17, 110 },{ -11, 97 }, { -20, 84 }, { -11, 79 },
- { -6, 73 }, { -4, 74 }, { -13, 86 }, { -13, 96 },
- { -11, 97 }, { -19, 117 },{ -8, 78 }, { -5, 33 },
- { -4, 48 }, { -2, 53 }, { -3, 62 }, { -13, 71 },
- { -10, 79 }, { -12, 86 }, { -13, 90 }, { -14, 97 },
-
- /* 276 a bit special (not used, x264_cabac_encode_bypass is used instead) */
- { 0, 0 },
-
- /* 277 -> 307 */
- { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 },
- { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 },
- { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 },
- { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 },
- { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 },
- { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 },
- { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 },
- { 9, 64 }, { -12, 104 },{ -11, 97 },
-
- /* 308 -> 337 */
- { -16, 96 }, { -7, 88 }, { -8, 85 }, { -7, 85 },
- { -9, 85 }, { -13, 88 }, { 4, 66 }, { -3, 77 },
- { -3, 76 }, { -6, 76 }, { 10, 58 }, { -1, 76 },
- { -1, 83 }, { -7, 99 }, { -14, 95 }, { 2, 95 },
- { 0, 76 }, { -5, 74 }, { 0, 70 }, { -11, 75 },
- { 1, 68 }, { 0, 65 }, { -14, 73 }, { 3, 62 },
- { 4, 62 }, { -1, 68 }, { -13, 75 }, { 11, 55 },
- { 5, 64 }, { 12, 70 },
-
- /* 338 -> 368 */
- { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 },
- { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 },
- { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 },
- { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 },
- { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 },
- { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 },
- { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 },
- { -12, 109 },{ 36, -35 }, { 36, -34 },
-
- /* 369 -> 398 */
- { 32, -26 }, { 37, -30 }, { 44, -32 }, { 34, -18 },
- { 34, -15 }, { 40, -15 }, { 33, -7 }, { 35, -5 },
- { 33, 0 }, { 38, 2 }, { 33, 13 }, { 23, 35 },
- { 13, 58 }, { 29, -3 }, { 26, 0 }, { 22, 30 },
- { 31, -7 }, { 35, -15 }, { 34, -3 }, { 34, 3 },
- { 36, -1 }, { 34, 5 }, { 32, 11 }, { 35, 5 },
- { 34, 12 }, { 39, 11 }, { 30, 29 }, { 34, 26 },
- { 29, 39 }, { 19, 66 }
-};
-
-static const int x264_cabac_context_init_PB[3][399][2] =
-{
- /* i_cabac_init_idc == 0 */
- {
- /* 0 - 10 */
- { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
- { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
- { -6, 53 }, { -1, 54 }, { 7, 51 },
-
- /* 11 - 23 */
- { 23, 33 }, { 23, 2 }, { 21, 0 }, { 1, 9 },
- { 0, 49 }, { -37, 118 }, { 5, 57 }, { -13, 78 },
- { -11, 65 }, { 1, 62 }, { 12, 49 }, { -4, 73 },
- { 17, 50 },
-
- /* 24 - 39 */
- { 18, 64 }, { 9, 43 }, { 29, 0 }, { 26, 67 },
- { 16, 90 }, { 9, 104 }, { -46, 127 }, { -20, 104 },
- { 1, 67 }, { -13, 78 }, { -11, 65 }, { 1, 62 },
- { -6, 86 }, { -17, 95 }, { -6, 61 }, { 9, 45 },
-
- /* 40 - 53 */
- { -3, 69 }, { -6, 81 }, { -11, 96 }, { 6, 55 },
- { 7, 67 }, { -5, 86 }, { 2, 88 }, { 0, 58 },
- { -3, 76 }, { -10, 94 }, { 5, 54 }, { 4, 69 },
- { -3, 81 }, { 0, 88 },
-
- /* 54 - 59 */
- { -7, 67 }, { -5, 74 }, { -4, 74 }, { -5, 80 },
- { -7, 72 }, { 1, 58 },
-
- /* 60 - 69 */
- { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
- { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
- { 13, 41 }, { 3, 62 },
-
- /* 70 - 87 */
- { 0, 45 }, { -4, 78 }, { -3, 96 }, { -27, 126 },
- { -28, 98 }, { -25, 101 }, { -23, 67 }, { -28, 82 },
- { -20, 94 }, { -16, 83 }, { -22, 110 }, { -21, 91 },
- { -18, 102 }, { -13, 93 }, { -29, 127 }, { -7, 92 },
- { -5, 89 }, { -7, 96 }, { -13, 108 }, { -3, 46 },
- { -1, 65 }, { -1, 57 }, { -9, 93 }, { -3, 74 },
- { -9, 92 }, { -8, 87 }, { -23, 126 }, { 5, 54 },
- { 6, 60 }, { 6, 59 }, { 6, 69 }, { -1, 48 },
- { 0, 68 }, { -4, 69 }, { -8, 88 },
-
- /* 105 -> 165 */
- { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 },
- { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 },
- { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 },
- { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 },
- { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 },
- { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 },
- { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 },
- { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 },
- { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 },
- { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 },
- { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 },
- { 3, 64 }, { 1, 61 }, { 9, 63 }, { 7, 50 },
- { 16, 39 }, { 5, 44 }, { 4, 52 }, { 11, 48 },
- { -5, 60 }, { -1, 59 }, { 0, 59 }, { 22, 33 },
- { 5, 44 }, { 14, 43 }, { -1, 78 }, { 0, 60 },
- { 9, 69 },
-
- /* 166 - 226 */
- { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 },
- { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 },
- { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 },
- { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 },
- { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 },
- { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 },
- { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 },
- { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 },
- { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 },
- { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 },
- { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 },
- { 1, 67 }, { 5, 59 }, { 9, 67 }, { 16, 30 },
- { 18, 32 }, { 18, 35 }, { 22, 29 }, { 24, 31 },
- { 23, 38 }, { 18, 43 }, { 20, 41 }, { 11, 63 },
- { 9, 59 }, { 9, 64 }, { -1, 94 }, { -2, 89 },
- { -9, 108 },
-
- /* 227 - 275 */
- { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 },
- { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 },
- { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 },
- { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 },
- { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 },
- { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 },
- { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 },
- { -3, 74 }, { -10, 90 }, { 0, 70 }, { -4, 29 },
- { 5, 31 }, { 7, 42 }, { 1, 59 }, { -2, 58 },
- { -3, 72 }, { -3, 81 }, { -11, 97 }, { 0, 58 },
- { 8, 5 }, { 10, 14 }, { 14, 18 }, { 13, 27 },
- { 2, 40 }, { 0, 58 }, { -3, 70 }, { -6, 79 },
- { -8, 85 },
-
- /* 276 a bit special (not used, x264_cabac_encode_bypass is used instead) */
- { 0, 0 },
-
- /* 277 - 337 */
- { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 },
- { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 },
- { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
- { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 },
- { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 },
- { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 },
- { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 },
- { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 },
- { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 },
- { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 },
- { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 },
- { -2, 69 }, { -2, 59 }, { 6, 70 }, { 10, 44 },
- { 9, 31 }, { 12, 43 }, { 3, 53 }, { 14, 34 },
- { 10, 38 }, { -3, 52 }, { 13, 40 }, { 17, 32 },
- { 7, 44 }, { 7, 38 }, { 13, 50 }, { 10, 57 },
- { 26, 43 },
-
- /* 338 - 398 */
- { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 },
- { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 },
- { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 },
- { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 },
- { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 },
- { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 },
- { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 },
- { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 },
- { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 },
- { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 },
- { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 },
- { 8, 60 }, { 6, 63 }, { 17, 65 }, { 21, 24 },
- { 23, 20 }, { 26, 23 }, { 27, 32 }, { 28, 23 },
- { 28, 24 }, { 23, 40 }, { 24, 32 }, { 28, 29 },
- { 23, 42 }, { 19, 57 }, { 22, 53 }, { 22, 61 },
- { 11, 86 },
-
-
- },
-
- /* i_cabac_init_idc == 1 */
- {
- /* 0 - 10 */
- { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
- { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
- { -6, 53 }, { -1, 54 }, { 7, 51 },
-
- /* 11 - 23 */
- { 22, 25 }, { 34, 0 }, { 16, 0 }, { -2, 9 },
- { 4, 41 }, { -29, 118 }, { 2, 65 }, { -6, 71 },
- { -13, 79 }, { 5, 52 }, { 9, 50 }, { -3, 70 },
- { 10, 54 },
-
- /* 24 - 39 */
- { 26, 34 }, { 19, 22 }, { 40, 0 }, { 57, 2 },
- { 41, 36 }, { 26, 69 }, { -45, 127 }, { -15, 101 },
- { -4, 76 }, { -6, 71 }, { -13, 79 }, { 5, 52 },
- { 6, 69 }, { -13, 90 }, { 0, 52 }, { 8, 43 },
-
- /* 40 - 53 */
- { -2, 69 },{ -5, 82 },{ -10, 96 },{ 2, 59 },
- { 2, 75 },{ -3, 87 },{ -3, 100 },{ 1, 56 },
- { -3, 74 },{ -6, 85 },{ 0, 59 },{ -3, 81 },
- { -7, 86 },{ -5, 95 },
-
- /* 54 - 59 */
- { -1, 66 },{ -1, 77 },{ 1, 70 },{ -2, 86 },
- { -5, 72 },{ 0, 61 },
-
- /* 60 - 69 */
- { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
- { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
- { 13, 41 }, { 3, 62 },
-
- /* 70 - 104 */
- { 13, 15 }, { 7, 51 }, { 2, 80 }, { -39, 127 },
- { -18, 91 }, { -17, 96 }, { -26, 81 }, { -35, 98 },
- { -24, 102 }, { -23, 97 }, { -27, 119 }, { -24, 99 },
- { -21, 110 }, { -18, 102 }, { -36, 127 }, { 0, 80 },
- { -5, 89 }, { -7, 94 }, { -4, 92 }, { 0, 39 },
- { 0, 65 }, { -15, 84 }, { -35, 127 }, { -2, 73 },
- { -12, 104 }, { -9, 91 }, { -31, 127 }, { 3, 55 },
- { 7, 56 }, { 7, 55 }, { 8, 61 }, { -3, 53 },
- { 0, 68 }, { -7, 74 }, { -9, 88 },
-
- /* 105 -> 165 */
- { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 },
- { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 },
- { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 },
- { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 },
- { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 },
- { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 },
- { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 },
- { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 },
- { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 },
- { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 },
- { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 },
- { -4, 71 }, { 0, 58 }, { 7, 61 }, { 9, 41 },
- { 18, 25 }, { 9, 32 }, { 5, 43 }, { 9, 47 },
- { 0, 44 }, { 0, 51 }, { 2, 46 }, { 19, 38 },
- { -4, 66 }, { 15, 38 }, { 12, 42 }, { 9, 34 },
- { 0, 89 },
-
- /* 166 - 226 */
- { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 },
- { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 },
- { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 },
- { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 },
- { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 },
- { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 },
- { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 },
- { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 },
- { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 },
- { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 },
- { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 },
- { 0, 75 }, { 2, 72 }, { 8, 77 }, { 14, 35 },
- { 18, 31 }, { 17, 35 }, { 21, 30 }, { 17, 45 },
- { 20, 42 }, { 18, 45 }, { 27, 26 }, { 16, 54 },
- { 7, 66 }, { 16, 56 }, { 11, 73 }, { 10, 67 },
- { -10, 116 },
-
- /* 227 - 275 */
- { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 },
- { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 },
- { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 },
- { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 },
- { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 },
- { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 },
- { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 },
- { -5, 74 }, { -9, 86 }, { 2, 66 }, { -9, 34 },
- { 1, 32 }, { 11, 31 }, { 5, 52 }, { -2, 55 },
- { -2, 67 }, { 0, 73 }, { -8, 89 }, { 3, 52 },
- { 7, 4 }, { 10, 8 }, { 17, 8 }, { 16, 19 },
- { 3, 37 }, { -1, 61 }, { -5, 73 }, { -1, 70 },
- { -4, 78 },
-
- /* 276 a bit special (not used, x264_cabac_encode_bypass is used instead) */
- { 0, 0 },
-
- /* 277 - 337 */
- { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
- { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
- { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
- { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 },
- { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 },
- { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 },
- { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 },
- { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 },
- { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 },
- { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 },
- { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 },
- { -1, 70 }, { -9, 72 }, { 14, 60 }, { 16, 37 },
- { 0, 47 }, { 18, 35 }, { 11, 37 }, { 12, 41 },
- { 10, 41 }, { 2, 48 }, { 12, 41 }, { 13, 41 },
- { 0, 59 }, { 3, 50 }, { 19, 40 }, { 3, 66 },
- { 18, 50 },
-
- /* 338 - 398 */
- { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 },
- { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 },
- { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 },
- { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 },
- { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 },
- { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 },
- { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 },
- { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 },
- { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 },
- { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 },
- { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 },
- { 12, 48 }, { 11, 49 }, { 26, 45 }, { 22, 22 },
- { 23, 22 }, { 27, 21 }, { 33, 20 }, { 26, 28 },
- { 30, 24 }, { 27, 34 }, { 18, 42 }, { 25, 39 },
- { 18, 50 }, { 12, 70 }, { 21, 54 }, { 14, 71 },
- { 11, 83 },
-
- },
-
- /* i_cabac_init_idc == 2 */
- {
- /* 0 - 10 */
- { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
- { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
- { -6, 53 }, { -1, 54 }, { 7, 51 },
-
- /* 11 - 23 */
- { 29, 16 }, { 25, 0 }, { 14, 0 }, { -10, 51 },
- { -3, 62 }, { -27, 99 }, { 26, 16 }, { -4, 85 },
- { -24, 102 }, { 5, 57 }, { 6, 57 }, { -17, 73 },
- { 14, 57 },
-
- /* 24 - 39 */
- { 20, 40 }, { 20, 10 }, { 29, 0 }, { 54, 0 },
- { 37, 42 }, { 12, 97 }, { -32, 127 }, { -22, 117 },
- { -2, 74 }, { -4, 85 }, { -24, 102 }, { 5, 57 },
- { -6, 93 }, { -14, 88 }, { -6, 44 }, { 4, 55 },
-
- /* 40 - 53 */
- { -11, 89 },{ -15, 103 },{ -21, 116 },{ 19, 57 },
- { 20, 58 },{ 4, 84 },{ 6, 96 },{ 1, 63 },
- { -5, 85 },{ -13, 106 },{ 5, 63 },{ 6, 75 },
- { -3, 90 },{ -1, 101 },
-
- /* 54 - 59 */
- { 3, 55 },{ -4, 79 },{ -2, 75 },{ -12, 97 },
- { -7, 50 },{ 1, 60 },
-
- /* 60 - 69 */
- { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
- { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
- { 13, 41 }, { 3, 62 },
-
- /* 70 - 104 */
- { 7, 34 }, { -9, 88 }, { -20, 127 }, { -36, 127 },
- { -17, 91 }, { -14, 95 }, { -25, 84 }, { -25, 86 },
- { -12, 89 }, { -17, 91 }, { -31, 127 }, { -14, 76 },
- { -18, 103 }, { -13, 90 }, { -37, 127 }, { 11, 80 },
- { 5, 76 }, { 2, 84 }, { 5, 78 }, { -6, 55 },
- { 4, 61 }, { -14, 83 }, { -37, 127 }, { -5, 79 },
- { -11, 104 }, { -11, 91 }, { -30, 127 }, { 0, 65 },
- { -2, 79 }, { 0, 72 }, { -4, 92 }, { -6, 56 },
- { 3, 68 }, { -8, 71 }, { -13, 98 },
-
- /* 105 -> 165 */
- { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 },
- { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 },
- { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 },
- { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 },
- { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 },
- { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 },
- { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 },
- { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 },
- { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 },
- { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 },
- { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 },
- { 3, 65 }, { -7, 69 }, { 8, 77 }, { -10, 66 },
- { 3, 62 }, { -3, 68 }, { -20, 81 }, { 0, 30 },
- { 1, 7 }, { -3, 23 }, { -21, 74 }, { 16, 66 },
- { -23, 124 }, { 17, 37 }, { 44, -18 }, { 50, -34 },
- { -22, 127 },
-
- /* 166 - 226 */
- { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 },
- { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 },
- { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 },
- { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 },
- { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 },
- { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 },
- { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 },
- { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 },
- { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 },
- { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 },
- { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 },
- { 20, 34 }, { 19, 31 }, { 27, 44 }, { 19, 16 },
- { 15, 36 }, { 15, 36 }, { 21, 28 }, { 25, 21 },
- { 30, 20 }, { 31, 12 }, { 27, 16 }, { 24, 42 },
- { 0, 93 }, { 14, 56 }, { 15, 57 }, { 26, 38 },
- { -24, 127 },
-
- /* 227 - 275 */
- { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 },
- { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 },
- { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 },
- { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 },
- { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 },
- { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 },
- { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 },
- { -12, 92 }, { -18, 108 }, { -4, 79 }, { -22, 69 },
- { -16, 75 }, { -2, 58 }, { 1, 58 }, { -13, 78 },
- { -9, 83 }, { -4, 81 }, { -13, 99 }, { -13, 81 },
- { -6, 38 }, { -13, 62 }, { -6, 58 }, { -2, 59 },
- { -16, 73 }, { -10, 76 }, { -13, 86 }, { -9, 83 },
- { -10, 87 },
-
- /* 276 a bit special (not used, x264_cabac_encode_bypass is used instead) */
- { 0, 0 },
-
- /* 277 - 337 */
- { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
- { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
- { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
- { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 },
- { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 },
- { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 },
- { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 },
- { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 },
- { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 },
- { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 },
- { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 },
- { -2, 76 }, { -18, 86 }, { 12, 70 }, { 5, 64 },
- { -12, 70 }, { 11, 55 }, { 5, 56 }, { 0, 69 },
- { 2, 65 }, { -6, 74 }, { 5, 54 }, { 7, 54 },
- { -6, 76 }, { -11, 82 }, { -2, 77 }, { -2, 77 },
- { 25, 42 },
-
- /* 338 - 398 */
- { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 },
- { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 },
- { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 },
- { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 },
- { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 },
- { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 },
- { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 },
- { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 },
- { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 },
- { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 },
- { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 },
- { 18, 31 }, { 19, 26 }, { 36, 24 }, { 24, 23 },
- { 27, 16 }, { 24, 30 }, { 31, 29 }, { 22, 41 },
- { 22, 42 }, { 16, 60 }, { 15, 52 }, { 14, 60 },
- { 3, 78 }, { -16, 123 }, { 21, 53 }, { 22, 56 },
- { 25, 61 },
- }
-};
-
-static const int x264_cabac_range_lps[64][4] =
-{
- { 128, 176, 208, 240 }, { 128, 167, 197, 227 }, { 128, 158, 187, 216 },
- { 123, 150, 178, 205 }, { 116, 142, 169, 195 }, { 111, 135, 160, 185 },
- { 105, 128, 152, 175 }, { 100, 122, 144, 166 }, { 95, 116, 137, 158 },
- { 90, 110, 130, 150 }, { 85, 104, 123, 142 }, { 81, 99, 117, 135 },
- { 77, 94, 111, 128 }, { 73, 89, 105, 122 }, { 69, 85, 100, 116 },
- { 66, 80, 95, 110 }, { 62, 76, 90, 104 }, { 59, 72, 86, 99 },
- { 56, 69, 81, 94 }, { 53, 65, 77, 89 }, { 51, 62, 73, 85 },
- { 48, 59, 69, 80 }, { 46, 56, 66, 76 }, { 43, 53, 63, 72 },
- { 41, 50, 59, 69 }, { 39, 48, 56, 65 }, { 37, 45, 54, 62 },
- { 35, 43, 51, 59 }, { 33, 41, 48, 56 }, { 32, 39, 46, 53 },
- { 30, 37, 43, 50 }, { 29, 35, 41, 48 }, { 27, 33, 39, 45 },
- { 26, 31, 37, 43 }, { 24, 30, 35, 41 }, { 23, 28, 33, 39 },
- { 22, 27, 32, 37 }, { 21, 26, 30, 35 }, { 20, 24, 29, 33 },
- { 19, 23, 27, 31 }, { 18, 22, 26, 30 }, { 17, 21, 25, 28 },
- { 16, 20, 23, 27 }, { 15, 19, 22, 25 }, { 14, 18, 21, 24 },
- { 14, 17, 20, 23 }, { 13, 16, 19, 22 }, { 12, 15, 18, 21 },
- { 12, 14, 17, 20 }, { 11, 14, 16, 19 }, { 11, 13, 15, 18 },
- { 10, 12, 15, 17 }, { 10, 12, 14, 16 }, { 9, 11, 13, 15 },
- { 9, 11, 12, 14 }, { 8, 10, 12, 14 }, { 8, 9, 11, 13 },
- { 7, 9, 11, 12 }, { 7, 9, 10, 12 }, { 7, 8, 10, 11 },
- { 6, 8, 9, 11 }, { 6, 7, 9, 10 }, { 6, 7, 8, 9 },
- { 2, 2, 2, 2 },
-};
-
-static const int x264_transition_lps[64] =
-{
- 0, 0, 1, 2, 2, 4, 4, 5, 6, 7, 8, 9, 9,11,11,12,
- 13,13,15,15,16,16,18,18,19,19,21,21,22,22,23,24,
- 24,25,26,26,27,27,28,29,29,30,30,30,31,32,32,33,
- 33,33,34,34,35,35,35,36,36,36,37,37,37,38,38,63
-};
-static const int x264_transition_mps[64] =
-{
- 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,
- 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
- 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
- 49,50,51,52,53,54,55,56,57,58,59,60,61,62,62,63,
-};
-
-#define FIX8(f) ((int)(f*(1<<8)))
-static int x264_cabac_probability[128] =
-{
- FIX8(0.9812), FIX8(0.9802), FIX8(0.9792), FIX8(0.9781),
- FIX8(0.9769), FIX8(0.9757), FIX8(0.9744), FIX8(0.9730),
- FIX8(0.9716), FIX8(0.9700), FIX8(0.9684), FIX8(0.9667),
- FIX8(0.9650), FIX8(0.9631), FIX8(0.9611), FIX8(0.9590),
- FIX8(0.9568), FIX8(0.9545), FIX8(0.9521), FIX8(0.9495),
- FIX8(0.9468), FIX8(0.9440), FIX8(0.9410), FIX8(0.9378),
- FIX8(0.9345), FIX8(0.9310), FIX8(0.9273), FIX8(0.9234),
- FIX8(0.9193), FIX8(0.9150), FIX8(0.9105), FIX8(0.9057),
- FIX8(0.9006), FIX8(0.8953), FIX8(0.8897), FIX8(0.8838),
- FIX8(0.8776), FIX8(0.8710), FIX8(0.8641), FIX8(0.8569),
- FIX8(0.8492), FIX8(0.8411), FIX8(0.8326), FIX8(0.8237),
- FIX8(0.8143), FIX8(0.8043), FIX8(0.7938), FIX8(0.7828),
- FIX8(0.7712), FIX8(0.7590), FIX8(0.7461), FIX8(0.7325),
- FIX8(0.7182), FIX8(0.7031), FIX8(0.6872), FIX8(0.6705),
- FIX8(0.6528), FIX8(0.6343), FIX8(0.6147), FIX8(0.5941),
- FIX8(0.5724), FIX8(0.5495), FIX8(0.5254), FIX8(0.5000),
- FIX8(0.5000), FIX8(0.4746), FIX8(0.4505), FIX8(0.4276),
- FIX8(0.4059), FIX8(0.3853), FIX8(0.3657), FIX8(0.3472),
- FIX8(0.3295), FIX8(0.3128), FIX8(0.2969), FIX8(0.2818),
- FIX8(0.2675), FIX8(0.2539), FIX8(0.2410), FIX8(0.2288),
- FIX8(0.2172), FIX8(0.2062), FIX8(0.1957), FIX8(0.1857),
- FIX8(0.1763), FIX8(0.1674), FIX8(0.1589), FIX8(0.1508),
- FIX8(0.1431), FIX8(0.1359), FIX8(0.1290), FIX8(0.1224),
- FIX8(0.1162), FIX8(0.1103), FIX8(0.1047), FIX8(0.0994),
- FIX8(0.0943), FIX8(0.0895), FIX8(0.0850), FIX8(0.0807),
- FIX8(0.0766), FIX8(0.0727), FIX8(0.0690), FIX8(0.0655),
- FIX8(0.0622), FIX8(0.0590), FIX8(0.0560), FIX8(0.0532),
- FIX8(0.0505), FIX8(0.0479), FIX8(0.0455), FIX8(0.0432),
- FIX8(0.0410), FIX8(0.0389), FIX8(0.0369), FIX8(0.0350),
- FIX8(0.0333), FIX8(0.0316), FIX8(0.0300), FIX8(0.0284),
- FIX8(0.0270), FIX8(0.0256), FIX8(0.0243), FIX8(0.0231),
- FIX8(0.0219), FIX8(0.0208), FIX8(0.0198), FIX8(0.0187)
-};
-/* -ln2(probability) */
-static int x264_cabac_entropy[128] =
-{
- FIX8(0.0273), FIX8(0.0288), FIX8(0.0303), FIX8(0.0320),
- FIX8(0.0337), FIX8(0.0355), FIX8(0.0375), FIX8(0.0395),
- FIX8(0.0416), FIX8(0.0439), FIX8(0.0463), FIX8(0.0488),
- FIX8(0.0515), FIX8(0.0543), FIX8(0.0572), FIX8(0.0604),
- FIX8(0.0637), FIX8(0.0671), FIX8(0.0708), FIX8(0.0747),
- FIX8(0.0788), FIX8(0.0832), FIX8(0.0878), FIX8(0.0926),
- FIX8(0.0977), FIX8(0.1032), FIX8(0.1089), FIX8(0.1149),
- FIX8(0.1214), FIX8(0.1282), FIX8(0.1353), FIX8(0.1429),
- FIX8(0.1510), FIX8(0.1596), FIX8(0.1686), FIX8(0.1782),
- FIX8(0.1884), FIX8(0.1992), FIX8(0.2107), FIX8(0.2229),
- FIX8(0.2358), FIX8(0.2496), FIX8(0.2642), FIX8(0.2798),
- FIX8(0.2964), FIX8(0.3142), FIX8(0.3331), FIX8(0.3532),
- FIX8(0.3748), FIX8(0.3979), FIX8(0.4226), FIX8(0.4491),
- FIX8(0.4776), FIX8(0.5082), FIX8(0.5412), FIX8(0.5768),
- FIX8(0.6152), FIX8(0.6568), FIX8(0.7020), FIX8(0.7513),
- FIX8(0.8050), FIX8(0.8638), FIX8(0.9285), FIX8(1.0000),
- FIX8(1.0000), FIX8(1.0752), FIX8(1.1504), FIX8(1.2256),
- FIX8(1.3008), FIX8(1.3759), FIX8(1.4511), FIX8(1.5263),
- FIX8(1.6015), FIX8(1.6767), FIX8(1.7519), FIX8(1.8271),
- FIX8(1.9023), FIX8(1.9775), FIX8(2.0527), FIX8(2.1278),
- FIX8(2.2030), FIX8(2.2782), FIX8(2.3534), FIX8(2.4286),
- FIX8(2.5038), FIX8(2.5790), FIX8(2.6542), FIX8(2.7294),
- FIX8(2.8046), FIX8(2.8797), FIX8(2.9549), FIX8(3.0301),
- FIX8(3.1053), FIX8(3.1805), FIX8(3.2557), FIX8(3.3309),
- FIX8(3.4061), FIX8(3.4813), FIX8(3.5565), FIX8(3.6316),
- FIX8(3.7068), FIX8(3.7820), FIX8(3.8572), FIX8(3.9324),
- FIX8(4.0076), FIX8(4.0828), FIX8(4.1580), FIX8(4.2332),
- FIX8(4.3083), FIX8(4.3836), FIX8(4.4588), FIX8(4.5339),
- FIX8(4.6091), FIX8(4.6843), FIX8(4.7595), FIX8(4.8347),
- FIX8(4.9099), FIX8(4.9851), FIX8(5.0602), FIX8(5.1354),
- FIX8(5.2106), FIX8(5.2859), FIX8(5.3610), FIX8(5.4362),
- FIX8(5.5114), FIX8(5.5866), FIX8(5.6618), FIX8(5.7370)
-};
-
-#undef FIX8
-
-
-/*****************************************************************************
- *
- *****************************************************************************/
-void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model )
-{
- const int (*cabac_context_init)[399][2];
- int i;
-
- if( i_slice_type == SLICE_TYPE_I )
- {
- cabac_context_init = &x264_cabac_context_init_I;
- }
- else
- {
- cabac_context_init = &x264_cabac_context_init_PB[i_model];
- }
-
- for( i = 0; i < 399; i++ )
- {
- int i_pre_state;
-
- i_pre_state = x264_clip3( (((*cabac_context_init)[i][0] * i_qp) >> 4) + (*cabac_context_init)[i][1], 1, 126 );
- if( i_pre_state <= 63 )
- {
- cb->ctxstate[i].i_state = 63 - i_pre_state;
- cb->ctxstate[i].i_mps = 0;
- }
- else
- {
- cb->ctxstate[i].i_state = i_pre_state - 64;
- cb->ctxstate[i].i_mps = 1;
- }
- cb->ctxstate[i].i_count = 0;
- }
-}
-
-/*****************************************************************************
- *
- *****************************************************************************/
-void x264_cabac_decode_init( x264_cabac_t *cb, bs_t *s )
-{
- cb->i_range = 0x01fe;
- cb->i_low = bs_read( s, 9 );
- cb->s = s;
-}
-
-static inline void x264_cabac_decode_renorm( x264_cabac_t *cb )
-{
- while( cb->i_range < 0x0100 )
- {
- cb->i_range <<= 1;
- cb->i_low = ( cb->i_low << 1 )|bs_read( cb->s, 1 );
- }
-}
-
-int x264_cabac_decode_decision( x264_cabac_t *cb, int i_ctx )
-{
- int i_state = cb->ctxstate[i_ctx].i_state;
- int i_mps = cb->ctxstate[i_ctx].i_mps;
-
- int i_range_lps = x264_cabac_range_lps[i_state][(cb->i_range>>6)&0x03];
-
- int val;
-
- cb->i_range -= i_range_lps;
-
- if( cb->i_low >= cb->i_range )
- {
- val = 1 - i_mps;
-
- cb->i_low -= cb->i_range;
- cb->i_range= i_range_lps;
-
- if( i_state == 0 )
- {
- cb->ctxstate[i_ctx].i_mps = 1 - i_mps;
- }
- cb->ctxstate[i_ctx].i_state = x264_transition_lps[i_state];
- }
- else
- {
- val = i_mps;
-
- cb->ctxstate[i_ctx].i_state = x264_transition_mps[i_state];
- }
-
- x264_cabac_decode_renorm( cb );
-
- return val;
-}
-int x264_cabac_decode_bypass( x264_cabac_t *cb )
-{
- cb->i_low = (cb->i_low << 1)|bs_read( cb->s, 1 );
-
- if( cb->i_low >= cb->i_range )
- {
- cb->i_low -= cb->i_range;
- return 1;
- }
- return 0;
-}
-int x264_cabac_decode_terminal( x264_cabac_t *cb )
-{
- if( cb->i_low >= cb->i_range - 2 )
- {
- return 1;
- }
-
- cb->i_range -= 2;
- x264_cabac_decode_renorm( cb );
- return 0;
-}
-
-
-/*****************************************************************************
- *
- *****************************************************************************/
-void x264_cabac_model_init( x264_cabac_t *cb )
-{
- int i;
-
- for( i = 0; i < 3; i++ )
- {
- cb->slice[i].i_model = 0;
- cb->slice[i].i_cost = -1;
- }
-}
-
-int x264_cabac_model_get ( x264_cabac_t *cb, int i_slice_type )
-{
- return cb->slice[i_slice_type].i_model;
-}
-
-void x264_cabac_model_update( x264_cabac_t *cb, int i_slice_type, int i_qp )
-{
- int i;
-
- if( i_slice_type == SLICE_TYPE_I )
- {
- return;
- }
- cb->slice[i_slice_type].i_cost = -1;
-
- for( i = 0; i < 3; i++ )
- {
- int i_ctx;
- int i_cost;
-
- i_cost = 0; /* fix8 */
-
- for( i_ctx = 0; i_ctx < 399; i_ctx++ )
- {
- int i_weight;
- int i_model_state;
- int i_ctx_state;
-
- i_weight = X264_MIN( (1<<8), (cb->ctxstate[i_ctx].i_count<<8) / 32 );
- i_model_state = x264_clip3( ((x264_cabac_context_init_PB[i][i_ctx][0] * i_qp)>>4) +
- x264_cabac_context_init_PB[i][i_ctx][1], 0, 127 );
- i_ctx_state = cb->ctxstate[i_ctx].i_mps ? 64 + cb->ctxstate[i_ctx].i_state : 63 - cb->ctxstate[i_ctx].i_state;
-
- i_cost += (i_weight * (( x264_cabac_probability[ i_ctx_state] * x264_cabac_entropy[ i_model_state] +
- x264_cabac_probability[127 - i_ctx_state] * x264_cabac_entropy[127 - i_model_state] ) >> 8))>>8;
- }
-
- if( cb->slice[i_slice_type].i_cost == -1 || cb->slice[i_slice_type].i_cost > i_cost )
- {
- cb->slice[i_slice_type].i_model= i;
- cb->slice[i_slice_type].i_cost = i_cost;
- }
- }
-}
-
-void x264_cabac_encode_init( x264_cabac_t *cb, bs_t *s )
-{
- cb->i_low = 0;
- cb->i_range = 0x01FE;
- cb->b_first_bit= 1;
- cb->i_bits_outstanding = 0;
- cb->i_sym_cnt = 0;
- cb->s = s;
-}
-
-static inline void x264_cabac_putbit( x264_cabac_t *cb, int b )
-{
- if( cb->b_first_bit )
- {
- cb->b_first_bit = 0;
- }
- else
- {
- bs_write1( cb->s, b );
- }
-
- while( cb->i_bits_outstanding > 0 )
- {
- bs_write1( cb->s, 1 - b );
- cb->i_bits_outstanding--;
- }
-}
-
-static inline void x264_cabac_encode_renorm( x264_cabac_t *cb )
-{
- /* RenormE */
- while( cb->i_range < 0x0100 )
- {
- if( cb->i_low < 0x100 )
- {
- x264_cabac_putbit( cb, 0 );
- }
- else
- {
- if( cb->i_low >= 0x200 )
- {
- cb->i_low -= 0x200;
- x264_cabac_putbit( cb, 1 );
- }
- else
- {
- cb->i_low -= 0x100;
- cb->i_bits_outstanding++;
- }
- }
-
- cb->i_range <<= 1;
- cb->i_low <<= 1;
- }
-}
-
-void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx, int b )
-{
- int i_state = cb->ctxstate[i_ctx].i_state;
- int i_mps = cb->ctxstate[i_ctx].i_mps;
-
- int i_range_lps = x264_cabac_range_lps[i_state][(cb->i_range>>6)&0x03];
-
-#ifdef TRACE
- if( binCount >= 0 )
- {
- fprintf( stderr, "%d ctx=%d b=%d\n", binCount, i_ctx, b );
- }
- fprintf( stderr, "%d 0x%04x %d %d\n", binCount++, cb->i_range, i_state, i_mps );
-#endif
-
- cb->i_range -= i_range_lps;
-
- if( b != i_mps )
- {
- cb->i_low += cb->i_range;
- cb->i_range = i_range_lps;
-
- if( i_state == 0 )
- {
- cb->ctxstate[i_ctx].i_mps = 1 - i_mps;
- }
- cb->ctxstate[i_ctx].i_state = x264_transition_lps[i_state];
- }
- else
- {
- cb->ctxstate[i_ctx].i_state = x264_transition_mps[i_state];
- }
- cb->ctxstate[i_ctx].i_count++;
-
- x264_cabac_encode_renorm( cb );
-
- cb->i_sym_cnt++;
-}
-
-void x264_cabac_encode_bypass( x264_cabac_t *cb, int b )
-{
-#ifdef TRACE
- fprintf( stderr, "%d 0x%04x\n", binCount++, cb->i_range );
-#endif
-
- cb->i_low <<= 1;
- if( b )
- {
- cb->i_low += cb->i_range;
- }
-
- if( cb->i_low >= 0x400 )
- {
- x264_cabac_putbit( cb, 1 );
- cb->i_low -= 0x400;
- }
- else
- {
- if( cb->i_low < 0x200 )
- {
- x264_cabac_putbit( cb, 0 );
- }
- else
- {
- cb->i_low -= 0x200;
- cb->i_bits_outstanding++;
- }
- }
- cb->i_sym_cnt++;
-}
-
-void x264_cabac_encode_terminal( x264_cabac_t *cb, int b )
-{
-#ifdef TRACE
- fprintf( stderr, "%d 0x%04x\n", binCount++, cb->i_range );
-#endif
-
- cb->i_range -= 2;
- if( b )
- {
- cb->i_low += cb->i_range;
- cb->i_range = 2;
- }
- x264_cabac_encode_renorm( cb );
-
- cb->i_sym_cnt++;
-}
-
-void x264_cabac_encode_flush( x264_cabac_t *cb )
-{
- x264_cabac_putbit( cb, (cb->i_low >> 9)&0x01 );
- bs_write1( cb->s, (cb->i_low >> 8)&0x01 );
-
- /* check that */
- bs_write1( cb->s, 0x01 );
- bs_align_0( cb->s );
-}
-
+++ /dev/null
-/*****************************************************************************
- * cabac.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: cabac.h,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifndef _CABAC_H
-#define _CABAC_H 1
-
-typedef struct
-{
- /* model */
- struct
- {
- int i_model;
- int i_cost;
- } slice[3];
-
- /* context */
- struct
- {
- int i_state;
- int i_mps;
- int i_count;
- } ctxstate[399];
-
- /* state */
- int i_low;
- int i_range;
-
- int i_sym_cnt;
-
- /* bit stream */
- int b_first_bit;
- int i_bits_outstanding;
- bs_t *s;
-
-} x264_cabac_t;
-
-/* encoder/decoder: init the contexts given i_slice_type, the quantif and the model */
-void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model );
-
-/* decoder only: */
-void x264_cabac_decode_init ( x264_cabac_t *cb, bs_t *s );
-int x264_cabac_decode_decision( x264_cabac_t *cb, int i_ctx_idx );
-int x264_cabac_decode_bypass ( x264_cabac_t *cb );
-int x264_cabac_decode_terminal( x264_cabac_t *cb );
-
-/* encoder only: adaptive model init */
-void x264_cabac_model_init( x264_cabac_t *cb );
-int x264_cabac_model_get ( x264_cabac_t *cb, int i_slice_type );
-void x264_cabac_model_update( x264_cabac_t *cb, int i_slice_type, int i_qp );
-/* encoder only: */
-void x264_cabac_encode_init ( x264_cabac_t *cb, bs_t *s );
-void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx_idx, int b );
-void x264_cabac_encode_bypass( x264_cabac_t *cb, int b );
-void x264_cabac_encode_terminal( x264_cabac_t *cb, int b );
-void x264_cabac_encode_flush( x264_cabac_t *cb );
-
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * clip1.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: clip1.h,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifndef _CLIP1_H
-#define _CLIP1_H 1
-
-/* Clip1 table
- * XXX : only for tap filter.
- *
- * With tap filter (( 1, -5, 20, 20, -5, 1 ) + 16 )/ 32
- * -> (-2*5 * 255+16)/32 <= out <= (2*1*255 + 2*20*255+16)/32
- * -> -80 <= out <= 335
- * So we need a table of 80+335+1 = 416 entries
- */
-
-static const uint8_t x264_mc_clip1_table[80+1+335] =
-{
- /* -80 -> -1 */
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,
- /* 0 -> 255 */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
- 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
- 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
- 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
- 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
- 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,101,102,103,104,105,106,107,
- 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
- 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
- 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,
- 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
- 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
- 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
- 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
- 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
- 252,253,254,255,
- /* 256 -> 340 */
- 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
- 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
- 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
- 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
- 255,255,255,255,255,255,255,255,
-};
-
-static inline uint8_t x264_mc_clip1( int x )
-{
- return x264_mc_clip1_table[x+80];
-}
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * common.c: h264 library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: common.c,v 1.1 2004/06/03 19:27:06 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 <stdarg.h>
-
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
-#include "common.h"
-#include "cpu.h"
-
-static void x264_log_default( void *, int, const char *, va_list );
-
-/****************************************************************************
- * x264_param_default:
- ****************************************************************************/
-void x264_param_default( x264_param_t *param )
-{
- /* */
- memset( param, 0, sizeof( x264_param_t ) );
-
- /* CPU autodetect */
- param->cpu = x264_cpu_detect();
-
- /* Video properties */
- param->i_csp = X264_CSP_I420;
- param->i_width = 0;
- param->i_height = 0;
- param->vui.i_sar_width = 0;
- param->vui.i_sar_height= 0;
- param->i_fps_num = 25;
- param->i_fps_den = 1;
-
- /* Encoder parameters */
- param->i_frame_reference = 1;
- param->i_idrframe = 2;
- param->i_iframe = 60;
- param->i_bframe = 0;
- param->i_scenecut_threshold = 40;
-
- param->b_deblocking_filter = 1;
- param->i_deblocking_filter_alphac0 = 0;
- param->i_deblocking_filter_beta = 0;
-
- param->b_cabac = 0;
- param->i_cabac_init_idc = -1;
-
- param->rc.b_cbr = 0;
- param->rc.i_bitrate = 3000;
- param->rc.i_rc_buffer_size = 0;
- param->rc.i_rc_init_buffer = 0;
- param->rc.i_rc_sens = 100;
- param->rc.i_qp_constant = 26;
- param->rc.i_qp_min = 0;
- param->rc.i_qp_max = 51;
- param->rc.i_qp_step = 4;
- param->rc.f_ip_factor = 1.4;
- param->rc.f_pb_factor = 1.4;
-
- param->rc.b_stat_write = 0;
- param->rc.psz_stat_out = "x264_2pass.log";
- param->rc.b_stat_read = 0;
- param->rc.psz_stat_in = "x264_2pass.log";
- param->rc.psz_rc_eq = "tex*blurTex^(qComp-1)";
- param->rc.f_qcompress = 0.6;
- param->rc.f_qblur = 0.5;
- param->rc.f_complexity_blur = 20;
-
- /* Log */
- param->pf_log = x264_log_default;
- param->p_log_private = NULL;
- param->i_log_level = X264_LOG_DEBUG;
-
- /* */
- param->analyse.intra = X264_ANALYSE_I4x4;
- param->analyse.inter = X264_ANALYSE_I4x4 | X264_ANALYSE_PSUB16x16;
- param->analyse.i_subpel_refine = 1;
- param->analyse.b_psnr = 1;
-}
-
-/****************************************************************************
- * x264_log:
- ****************************************************************************/
-void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... )
-{
- if( i_level <= h->param.i_log_level )
- {
- va_list arg;
- va_start( arg, psz_fmt );
- h->param.pf_log( h->param.p_log_private, i_level, psz_fmt, arg );
- va_end( arg );
- }
-}
-
-static void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg )
-{
- char *psz_prefix;
- switch( i_level )
- {
- case X264_LOG_ERROR:
- psz_prefix = "error";
- break;
- case X264_LOG_WARNING:
- psz_prefix = "warning";
- break;
- case X264_LOG_INFO:
- psz_prefix = "info";
- break;
- case X264_LOG_DEBUG:
- psz_prefix = "debug";
- break;
- default:
- psz_prefix = "unknown";
- break;
- }
- fprintf( stderr, "x264 [%s]: ", psz_prefix );
- vfprintf( stderr, psz_fmt, arg );
-}
-
-/****************************************************************************
- * x264_picture_alloc:
- ****************************************************************************/
-void x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height )
-{
- pic->i_type = X264_TYPE_AUTO;
- pic->i_qpplus1 = 0;
- pic->img.i_csp = i_csp;
- switch( i_csp & X264_CSP_MASK )
- {
- case X264_CSP_I420:
- case X264_CSP_YV12:
- pic->img.i_plane = 3;
- pic->img.plane[0] = x264_malloc( 3 * i_width * i_height / 2 );
- pic->img.plane[1] = pic->img.plane[0] + i_width * i_height;
- pic->img.plane[2] = pic->img.plane[1] + i_width * i_height / 4;
- pic->img.i_stride[0] = i_width;
- pic->img.i_stride[1] = i_width / 2;
- pic->img.i_stride[2] = i_width / 2;
- break;
-
- case X264_CSP_I422:
- pic->img.i_plane = 3;
- pic->img.plane[0] = x264_malloc( 2 * i_width * i_height );
- pic->img.plane[1] = pic->img.plane[0] + i_width * i_height;
- pic->img.plane[2] = pic->img.plane[1] + i_width * i_height / 2;
- pic->img.i_stride[0] = i_width;
- pic->img.i_stride[1] = i_width / 2;
- pic->img.i_stride[2] = i_width / 2;
- break;
-
- case X264_CSP_I444:
- pic->img.i_plane = 3;
- pic->img.plane[0] = x264_malloc( 3 * i_width * i_height );
- pic->img.plane[1] = pic->img.plane[0] + i_width * i_height;
- pic->img.plane[2] = pic->img.plane[1] + i_width * i_height;
- pic->img.i_stride[0] = i_width;
- pic->img.i_stride[1] = i_width;
- pic->img.i_stride[2] = i_width;
- break;
-
- case X264_CSP_YUYV:
- pic->img.i_plane = 1;
- pic->img.plane[0] = x264_malloc( 2 * i_width * i_height );
- pic->img.i_stride[0] = 2 * i_width;
- break;
-
- case X264_CSP_RGB:
- case X264_CSP_BGR:
- pic->img.i_plane = 1;
- pic->img.plane[0] = x264_malloc( 3 * i_width * i_height );
- pic->img.i_stride[0] = 3 * i_width;
- break;
-
- case X264_CSP_BGRA:
- pic->img.i_plane = 1;
- pic->img.plane[0] = x264_malloc( 4 * i_width * i_height );
- pic->img.i_stride[0] = 4 * i_width;
- break;
-
- default:
- fprintf( stderr, "invalid CSP\n" );
- pic->img.i_plane = 0;
- break;
- }
-}
-
-/****************************************************************************
- * x264_picture_clean:
- ****************************************************************************/
-void x264_picture_clean( x264_picture_t *pic )
-{
- x264_free( pic->img.plane[0] );
-
- /* just to be safe */
- memset( pic, 0, sizeof( x264_picture_t ) );
-}
-
-/****************************************************************************
- * x264_nal_encode:
- ****************************************************************************/
-int x264_nal_encode( void *p_data, int *pi_data, int b_annexeb, x264_nal_t *nal )
-{
- uint8_t *dst = p_data;
- uint8_t *src = nal->p_payload;
- uint8_t *end = &nal->p_payload[nal->i_payload];
-
- int i_count = 0;
-
- /* FIXME this code doesn't check overflow */
-
- if( b_annexeb )
- {
- /* long nal start code (we always use long ones)*/
- *dst++ = 0x00;
- *dst++ = 0x00;
- *dst++ = 0x00;
- *dst++ = 0x01;
- }
-
- /* nal header */
- *dst++ = ( 0x00 << 7 ) | ( nal->i_ref_idc << 5 ) | nal->i_type;
-
- while( src < end )
- {
- if( i_count == 2 && *src <= 0x03 )
- {
- *dst++ = 0x03;
- i_count = 0;
- }
- if( *src == 0 )
- {
- i_count++;
- }
- else
- {
- i_count = 0;
- }
- *dst++ = *src++;
- }
- *pi_data = dst - (uint8_t*)p_data;
-
- return *pi_data;
-}
-
-/****************************************************************************
- * x264_nal_decode:
- ****************************************************************************/
-int x264_nal_decode( x264_nal_t *nal, void *p_data, int i_data )
-{
- uint8_t *src = p_data;
- uint8_t *end = &src[i_data];
- uint8_t *dst = nal->p_payload;
-
- nal->i_type = src[0]&0x1f;
- nal->i_ref_idc = (src[0] >> 5)&0x03;
-
- src++;
-
- while( src < end )
- {
- if( src < end - 3 && src[0] == 0x00 && src[1] == 0x00 && src[2] == 0x03 )
- {
- *dst++ = 0x00;
- *dst++ = 0x00;
-
- src += 3;
- continue;
- }
- *dst++ = *src++;
- }
-
- nal->i_payload = dst - (uint8_t*)p_data;
- return 0;
-}
-
-
-
-/****************************************************************************
- * x264_malloc:
- ****************************************************************************/
-void *x264_malloc( int i_size )
-{
-#ifdef SYS_MACOSX
- /* Mac OS X always returns 16 bytes aligned memory */
- return malloc( i_size );
-#elif defined( HAVE_MALLOC_H )
- return memalign( 16, i_size );
-#else
- uint8_t * buf;
- uint8_t * align_buf;
- buf = (uint8_t *) malloc( i_size + 15 + sizeof( void ** ) +
- sizeof( int ) );
- align_buf = buf + 15 + sizeof( void ** ) + sizeof( int );
- align_buf -= (long) align_buf & 15;
- *( (void **) ( align_buf - sizeof( void ** ) ) ) = buf;
- *( (int *) ( align_buf - sizeof( void ** ) - sizeof( int ) ) ) = i_size;
- return align_buf;
-#endif
-}
-
-/****************************************************************************
- * x264_free:
- ****************************************************************************/
-void x264_free( void *p )
-{
- if( p )
- {
-#if defined( HAVE_MALLOC_H ) || defined( SYS_MACOSX )
- free( p );
-#else
- free( *( ( ( void **) p ) - 1 ) );
-#endif
- }
-}
-
-/****************************************************************************
- * x264_realloc:
- ****************************************************************************/
-void *x264_realloc( void *p, int i_size )
-{
-#ifdef HAVE_MALLOC_H
- return realloc( p, i_size );
-#else
- int i_old_size = 0;
- uint8_t * p_new;
- if( p )
- {
- i_old_size = *( (int*) ( (uint8_t*) p ) - sizeof( void ** ) -
- sizeof( int ) );
- }
- p_new = x264_malloc( i_size );
- if( i_old_size > 0 && i_size > 0 )
- {
- memcpy( p_new, p, ( i_old_size < i_size ) ? i_old_size : i_size );
- }
- x264_free( p );
- return p_new;
-#endif
-}
-
+++ /dev/null
-/*****************************************************************************
- * common.h: h264 encoder
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: common.h,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifndef _COMMON_H
-#define _COMMON_H 1
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdarg.h>
-
-#include "../x264.h"
-#include "bs.h"
-#include "set.h"
-#include "predict.h"
-#include "pixel.h"
-#include "mc.h"
-#include "frame.h"
-#include "dct.h"
-#include "cabac.h"
-#include "csp.h"
-
-/****************************************************************************
- * Macros
- ****************************************************************************/
-#define X264_MIN(a,b) ( (a)<(b) ? (a) : (b) )
-#define X264_MAX(a,b) ( (a)>(b) ? (a) : (b) )
-#define X264_ABS(a) ( (a)< 0 ? -(a) : (a) )
-
-/****************************************************************************
- * Generals functions
- ****************************************************************************/
-/* x264_malloc : will do or emulate a memalign
- * XXX you HAVE TO use x264_free for buffer allocated
- * with x264_malloc
- */
-void *x264_malloc( int );
-void *x264_realloc( void *p, int i_size );
-void x264_free( void * );
-
-/* mdate: return the current date in microsecond */
-int64_t x264_mdate( void );
-
-/* log */
-void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... );
-
-static inline int x264_clip3( int v, int i_min, int i_max )
-{
- return ( (v < i_min) ? i_min : (v > i_max) ? i_max : v );
-}
-
-static inline float x264_clip3f( float v, float f_min, float f_max )
-{
- return ( (v < f_min) ? f_min : (v > f_max) ? f_max : v );
-}
-
-/****************************************************************************
- *
- ****************************************************************************/
-enum slice_type_e
-{
- SLICE_TYPE_P = 0,
- SLICE_TYPE_B = 1,
- SLICE_TYPE_I = 2,
- SLICE_TYPE_SP = 3,
- SLICE_TYPE_SI = 4
-};
-
-typedef struct
-{
- x264_sps_t *sps;
- x264_pps_t *pps;
-
- int i_type;
- int i_first_mb;
-
- int i_pps_id;
-
- int i_frame_num;
-
- int b_field_pic;
- int b_bottom_field;
-
- int i_idr_pic_id; /* -1 if nal_type != 5 */
-
- int i_poc_lsb;
- int i_delta_poc_bottom;
-
- int i_delta_poc[2];
- int i_redundant_pic_cnt;
-
- int b_direct_spatial_mv_pred;
-
- int b_num_ref_idx_override;
- int i_num_ref_idx_l0_active;
- int i_num_ref_idx_l1_active;
-
- int i_cabac_init_idc;
-
- int i_qp_delta;
- int b_sp_for_swidth;
- int i_qs_delta;
-
- /* deblocking filter */
- int i_disable_deblocking_filter_idc;
- int i_alpha_c0_offset;
- int i_beta_offset;
-
-} x264_slice_header_t;
-
-/* From ffmpeg
- */
-#define X264_SCAN8_SIZE (6*8)
-#define X264_SCAN8_0 (4+1*8)
-
-static const int x264_scan8[16+2*4] =
-{
- /* Luma */
- 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,
-
- /* Cb */
- 1+1*8, 2+1*8,
- 1+2*8, 2+2*8,
-
- /* Cr */
- 1+4*8, 2+4*8,
- 1+5*8, 2+5*8,
-};
-/*
- 0 1 2 3 4 5 6 7
- 0
- 1 B B L L L L
- 2 B B L L L L
- 3 L L L L
- 4 R R L L L L
- 5 R R
-*/
-
-#define X264_BFRAME_MAX 16
-
-typedef struct x264_ratecontrol_t x264_ratecontrol_t;
-typedef struct x264_vlc_table_t x264_vlc_table_t;
-
-struct x264_t
-{
- /* encoder parameters */
- x264_param_t param;
-
- /* bitstream output */
- struct
- {
- int i_nal;
- x264_nal_t nal[3]; /* for now 3 is enought */
- int i_bitstream; /* size of p_bitstream */
- uint8_t *p_bitstream; /* will hold data for all nal */
- bs_t bs;
- } out;
-
- /* frame number/poc */
- int i_frame;
- int i_poc;
-
- int i_frame_offset; /* decoding only */
- int i_frame_num; /* decoding only */
- int i_poc_msb; /* decoding only */
- int i_poc_lsb; /* decoding only */
-
- /* We use only one SPS and one PPS */
- x264_sps_t sps_array[32];
- x264_sps_t *sps;
- x264_pps_t pps_array[256];
- x264_pps_t *pps;
- int i_idr_pic_id;
-
- /* Slice header */
- x264_slice_header_t sh;
-
- /* cabac context */
- x264_cabac_t cabac;
-
- struct
- {
- /* Frames to be encoded */
- x264_frame_t *current[X264_BFRAME_MAX+1];
- /* Temporary buffer (eg B frames pending until we reach the I/P) */
- x264_frame_t *next[X264_BFRAME_MAX+1];
- /* Unused frames */
- x264_frame_t *unused[X264_BFRAME_MAX+1];
-
- /* frames used for reference +1 for decoding */
- x264_frame_t *reference[16+1];
-
- int i_last_idr; /* How many I non IDR frames from last IDR */
- int i_last_i; /* How many P/B frames from last I */
-
- int i_input; /* Number of input frames already accepted */
- } frames;
-
- /* current frame being encoded */
- x264_frame_t *fenc;
-
- /* frame being reconstructed */
- x264_frame_t *fdec;
-
- /* references lists */
- int i_ref0;
- x264_frame_t *fref0[16]; /* ref list 0 */
- int i_ref1;
- x264_frame_t *fref1[16]; /* ref list 1 */
-
-
-
- /* Current MB DCT coeffs */
- struct
- {
- DECLARE_ALIGNED( int, luma16x16_dc[16], 16 );
- DECLARE_ALIGNED( int, chroma_dc[2][4], 16 );
- union
- {
- DECLARE_ALIGNED( int, residual_ac[15], 16 );
- DECLARE_ALIGNED( int, luma4x4[16], 16 );
- } block[16+8];
- } dct;
-
- /* MB table and cache for current frame/mb */
- struct
- {
- /* Strides */
- int i_mb_stride;
-
- /* Current index */
- int i_mb_x;
- int i_mb_y;
- int i_mb_xy;
-
- unsigned int i_neighbour;
-
- /* mb table */
- int8_t *type; /* mb type */
- int8_t *qp; /* mb qp */
- int16_t *cbp; /* mb cbp: 0x0?: luma, 0x?0: chroma, 0x100: luma dc, 0x0200 and 0x0400: chroma dc (all set for PCM)*/
- int8_t (*intra4x4_pred_mode)[7]; /* intra4x4 pred mode. for non I4x4 set to I_PRED_4x4_DC(2) */
- uint8_t (*non_zero_count)[16+4+4]; /* nzc. for I_PCM set to 16 */
- int8_t *chroma_pred_mode; /* chroma_pred_mode. cabac only. for non intra I_PRED_CHROMA_DC(0) */
- int16_t (*mv[2])[2]; /* mb mv. set to 0 for intra mb */
- int16_t (*mvd[2])[2]; /* mb mv difference with predict. set to 0 if intra. cabac only */
- int8_t *ref[2]; /* mb ref. set to -1 if non used (intra or Lx only) */
- int16_t (*mvr[2][16])[2]; /* mb mv for each possible ref */
-
- /* current value */
- int i_type;
- int i_partition;
- int i_sub_partition[4];
-
- int i_cbp_luma;
- int i_cbp_chroma;
-
- int i_intra16x16_pred_mode;
- int i_chroma_pred_mode;
-
- struct
- {
- /* pointer over mb of the frame to be compressed */
- uint8_t *p_fenc[3];
-
- /* pointer over mb of the frame to be reconstrucated */
- uint8_t *p_fdec[3];
-
- /* pointer over mb of the references */
- uint8_t *p_fref[2][16][3];
-
- /* common stride */
- int i_stride[3];
- } pic;
-
- /* cache */
- struct
- {
- /* real intra4x4_pred_mode if I_4X4, I_PRED_4x4_DC if mb available, -1 if not */
- int intra4x4_pred_mode[X264_SCAN8_SIZE];
-
- /* i_non_zero_count if availble else 0x80 */
- int non_zero_count[X264_SCAN8_SIZE];
-
- /* -1 if unused, -2 if unavaible */
- int8_t ref[2][X264_SCAN8_SIZE];
-
- /* 0 if non avaible */
- int16_t mv[2][X264_SCAN8_SIZE][2];
- int16_t mvd[2][X264_SCAN8_SIZE][2];
- } cache;
-
- /* */
- int i_last_qp; /* last qp */
- int i_last_dqp; /* last delta qp */
-
- } mb;
-
- /* rate control encoding only */
- x264_ratecontrol_t *rc;
-
- int i_last_inter_size;
- int i_last_intra_size;
- int i_last_intra_qp;
-
- /* stats */
- struct
- {
- /* Current frame stats */
- struct
- {
- /* Headers bits (MV+Ref+MB Block Type */
- int i_hdr_bits;
- /* Texture bits (Intra/Predicted) */
- int i_itex_bits;
- int i_ptex_bits;
- /* ? */
- int i_misc_bits;
- /* MB type counts */
- int i_mb_count[18];
- int i_mb_count_p;
- int i_mb_count_skip;
- /* Estimated (SATD) cost as Intra/Predicted frame */
- /* XXX: both omit the cost of MBs coded as P_SKIP */
- int i_intra_cost;
- int i_inter_cost;
- } frame;
-
- /* Cummulated stats */
-
- /* per slice info */
- int i_slice_count[5];
- int64_t i_slice_size[5];
- int i_slice_qp[5];
- /* */
- int64_t i_sqe_global[5];
- float f_psnr_average[5];
- float f_psnr_mean_y[5];
- float f_psnr_mean_u[5];
- float f_psnr_mean_v[5];
- /* */
- int64_t i_mb_count[5][18];
-
- } stat;
-
- /* CPU functions dependants */
- x264_predict_t predict_16x16[4+3];
- x264_predict_t predict_8x8[4+3];
- x264_predict_t predict_4x4[9+3];
-
- x264_pixel_function_t pixf;
- x264_mc_function_t mc[2];
- x264_dct_function_t dctf;
- x264_csp_function_t csp;
-
- /* vlc table for decoding purpose only */
- x264_vlc_table_t *x264_coeff_token_lookup[5];
- x264_vlc_table_t *x264_level_prefix_lookup;
- x264_vlc_table_t *x264_total_zeros_lookup[15];
- x264_vlc_table_t *x264_total_zeros_dc_lookup[3];
- x264_vlc_table_t *x264_run_before_lookup[7];
-};
-
-#endif
-
+++ /dev/null
-/*****************************************************************************
- * cpu.c: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: cpu.c,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "../x264.h"
-#include "cpu.h"
-
-#ifdef ARCH_X86
-extern int x264_cpu_cpuid_test( void );
-extern uint32_t x264_cpu_cpuid( uint32_t op, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx );
-extern void x264_emms( void );
-
-uint32_t x264_cpu_detect( void )
-{
- uint32_t cpu = 0;
-
- uint32_t eax, ebx, ecx, edx;
- int b_amd;
-
-
- if( !x264_cpu_cpuid_test() )
- {
- /* No cpuid */
- return 0;
- }
-
- x264_cpu_cpuid( 0, &eax, &ebx, &ecx, &edx);
- if( eax == 0 )
- {
- return 0;
- }
- b_amd = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
-
- x264_cpu_cpuid( 1, &eax, &ebx, &ecx, &edx );
- if( (edx&0x00800000) == 0 )
- {
- /* No MMX */
- return 0;
- }
- cpu = X264_CPU_MMX;
- if( (edx&0x02000000) )
- {
- /* SSE - identical to AMD MMX extensions */
- cpu |= X264_CPU_MMXEXT|X264_CPU_SSE;
- }
- if( (edx&0x04000000) )
- {
- /* Is it OK ? */
- cpu |= X264_CPU_SSE2;
- }
-
- x264_cpu_cpuid( 0x80000000, &eax, &ebx, &ecx, &edx );
- if( eax < 0x80000001 )
- {
- /* no extended capabilities */
- return cpu;
- }
-
- x264_cpu_cpuid( 0x80000001, &eax, &ebx, &ecx, &edx );
- if( edx&0x80000000 )
- {
- cpu |= X264_CPU_3DNOW;
- }
- if( b_amd && (edx&0x00400000) )
- {
- /* AMD MMX extensions */
- cpu |= X264_CPU_MMXEXT;
- }
-
- return cpu;
-}
-
-void x264_cpu_restore( uint32_t cpu )
-{
- if( cpu&(X264_CPU_MMX|X264_CPU_MMXEXT|X264_CPU_3DNOW|X264_CPU_3DNOWEXT) )
- {
- x264_emms();
- }
-}
-
-
-#if 0
-/*
- * XXX: adapted from libmpeg2 */
-#if 0
-#define cpuid(op,eax,ebx,ecx,edx) \
- __asm__ ("push %%ebx\n\t" \
- "cpuid\n\t" \
- "movl %%ebx,%1\n\t" \
- "pop %%ebx" \
- : "=a" (eax), \
- "=r" (ebx), \
- "=c" (ecx), \
- "=d" (edx) \
- : "a" (op) \
- : "cc")
-#endif
-
-uint32_t x264_cpu_detect( void )
-{
- uint32_t cpu = 0;
-
- uint32_t eax, ebx, ecx, edx;
- int b_amd;
-
-
- /* Test if cpuid is supported */
- asm volatile(
- "pushf\n"
- "pushf\n"
- "pop %0\n"
- "movl %0,%1\n"
- "xorl $0x200000,%0\n"
- "push %0\n"
- "popf\n"
- "pushf\n"
- "pop %0\n"
- "popf\n"
- : "=r" (eax), "=r" (ebx) : : "cc");
-
- if( eax == ebx )
- {
- /* No cpuid */
- return 0;
- }
-
- cpuid( 0, eax, ebx, ecx, edx);
- if( eax == 0 )
- {
- return 0;
- }
- b_amd = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
-
- cpuid( 1, eax, ebx, ecx, edx );
- if( (edx&0x00800000) == 0 )
- {
- /* No MMX */
- return 0;
- }
- cpu = X264_CPU_MMX;
- if( (edx&0x02000000) )
- {
- /* SSE - identical to AMD MMX extensions */
- cpu |= X264_CPU_MMXEXT|X264_CPU_SSE;
- }
- if( (edx&0x04000000) )
- {
- /* Is it OK ? */
- cpu |= X264_CPU_SSE2;
- }
-
- cpuid( 0x80000000, eax, ebx, ecx, edx );
- if( eax < 0x80000001 )
- {
- /* no extended capabilities */
- return cpu;
- }
-
- cpuid( 0x80000001, eax, ebx, ecx, edx );
- if( edx&0x80000000 )
- {
- cpu |= X264_CPU_3DNOW;
- }
- if( b_amd && (edx&0x00400000) )
- {
- /* AMD MMX extensions */
- cpu |= X264_CPU_MMXEXT;
- }
-
- return cpu;
-}
-#endif
-
-#elif defined( ARCH_PPC )
-
-#ifdef SYS_MACOSX
-#include <sys/sysctl.h>
-uint32_t x264_cpu_detect( void )
-{
- /* Thank you VLC */
- uint32_t cpu = 0;
- int selectors[2] = { CTL_HW, HW_VECTORUNIT };
- int has_altivec = 0;
- size_t length = sizeof( has_altivec );
- int error = sysctl( selectors, 2, &has_altivec, &length, NULL, 0 );
-
- if( error == 0 && has_altivec != 0 )
- {
- cpu |= X264_CPU_ALTIVEC;
- }
-
- return cpu;
-}
-
-#elif defined( SYS_LINUX )
-uint32_t x264_cpu_detect( void )
-{
- /* FIXME (Linux PPC) */
- return X264_CPU_ALTIVEC;
-}
-#endif
-
-void x264_cpu_restore( uint32_t cpu )
-{
-}
-
-#else
-
-uint32_t x264_cpu_detect( void )
-{
- return 0;
-}
-
-void x264_cpu_restore( uint32_t cpu )
-{
-}
-
-#endif
-
+++ /dev/null
-/*****************************************************************************
- * cpu.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: cpu.h,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifndef _CPU_H
-#define _CPU_H 1
-
-uint32_t x264_cpu_detect( void );
-
-/* probably MMX(EXT) centric but .... */
-void x264_cpu_restore( uint32_t cpu );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * csp.c: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2004 Laurent Aimar
- * $Id: csp.c,v 1.1 2004/06/03 19:27:06 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 "common.h"
-
-static inline void plane_copy( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src, int w, int h)
-{
- for( ; h > 0; h-- )
- {
- memcpy( dst, src, w );
- dst += i_dst;
- src += i_src;
- }
-}
-static inline void plane_copy_vflip( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src, int w, int h)
-{
- plane_copy( dst, i_dst, src + (h -1)*i_src, -i_src, w, h );
-}
-
-static inline void plane_subsamplev2( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src, int w, int h)
-{
- for( ; h > 0; h-- )
- {
- uint8_t *d = dst;
- uint8_t *s = src;
- int i;
- for( i = 0; i < w; i++ )
- {
- *d++ = ( s[0] + s[i_src] + 1 ) >> 1;
- s++;
- }
- dst += i_dst;
- src += 2 * i_src;
- }
-}
-
-static inline void plane_subsamplev2_vlip( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src, int w, int h)
-{
- plane_subsamplev2( dst, i_dst, src + (2*h-1)*i_src, -i_src, w, h );
-}
-
-static inline void plane_subsamplehv2( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src, int w, int h)
-{
- for( ; h > 0; h-- )
- {
- uint8_t *d = dst;
- uint8_t *s = src;
- int i;
- for( i = 0; i < w; i++ )
- {
- *d++ = ( s[0] + s[1] + s[i_src] + s[i_src+1] + 1 ) >> 2;
- s += 2;
- }
- dst += i_dst;
- src += 2 * i_src;
- }
-}
-
-static inline void plane_subsamplehv2_vlip( uint8_t *dst, int i_dst,
- uint8_t *src, int i_src, int w, int h)
-{
- plane_subsamplehv2( dst, i_dst, src + (2*h-1)*i_src, -i_src, w, h );
-}
-
-static void i420_to_i420( x264_frame_t *frm, x264_image_t *img,
- int i_width, int i_height )
-{
- if( img->i_csp & X264_CSP_VFLIP )
- {
- plane_copy_vflip( frm->plane[0], frm->i_stride[0],
- img->plane[0], img->i_stride[0],
- i_width, i_height );
- plane_copy_vflip( frm->plane[1], frm->i_stride[1],
- img->plane[1], img->i_stride[1],
- i_width / 2, i_height / 2 );
- plane_copy_vflip( frm->plane[2], frm->i_stride[2],
- img->plane[2], img->i_stride[2],
- i_width / 2, i_height / 2 );
- }
- else
- {
- plane_copy( frm->plane[0], frm->i_stride[0],
- img->plane[0], img->i_stride[0],
- i_width, i_height );
- plane_copy( frm->plane[1], frm->i_stride[1],
- img->plane[1], img->i_stride[1],
- i_width / 2, i_height / 2 );
- plane_copy( frm->plane[2], frm->i_stride[2],
- img->plane[2], img->i_stride[2],
- i_width / 2, i_height / 2 );
- }
-}
-
-static void yv12_to_i420( x264_frame_t *frm, x264_image_t *img,
- int i_width, int i_height )
-{
- if( img->i_csp & X264_CSP_VFLIP )
- {
- plane_copy_vflip( frm->plane[0], frm->i_stride[0],
- img->plane[0], img->i_stride[0],
- i_width, i_height );
- plane_copy_vflip( frm->plane[2], frm->i_stride[2],
- img->plane[1], img->i_stride[1],
- i_width / 2, i_height / 2 );
- plane_copy_vflip( frm->plane[1], frm->i_stride[1],
- img->plane[2], img->i_stride[2],
- i_width / 2, i_height / 2 );
- }
- else
- {
- plane_copy( frm->plane[0], frm->i_stride[0],
- img->plane[0], img->i_stride[0],
- i_width, i_height );
- plane_copy( frm->plane[2], frm->i_stride[2],
- img->plane[1], img->i_stride[1],
- i_width / 2, i_height / 2 );
- plane_copy( frm->plane[1], frm->i_stride[1],
- img->plane[2], img->i_stride[2],
- i_width / 2, i_height / 2 );
- }
-}
-
-static void i422_to_i420( x264_frame_t *frm, x264_image_t *img,
- int i_width, int i_height )
-{
- if( img->i_csp & X264_CSP_VFLIP )
- {
- plane_copy_vflip( frm->plane[0], frm->i_stride[0],
- img->plane[0], img->i_stride[0],
- i_width, i_height );
-
- plane_subsamplev2_vlip( frm->plane[1], frm->i_stride[1],
- img->plane[1], img->i_stride[1],
- i_width / 2, i_height / 2 );
- plane_subsamplev2_vlip( frm->plane[2], frm->i_stride[2],
- img->plane[2], img->i_stride[2],
- i_width / 2, i_height / 2 );
- }
- else
- {
- plane_copy( frm->plane[0], frm->i_stride[0],
- img->plane[0], img->i_stride[0],
- i_width, i_height );
-
- plane_subsamplev2( frm->plane[1], frm->i_stride[1],
- img->plane[1], img->i_stride[1],
- i_width / 2, i_height / 2 );
- plane_subsamplev2( frm->plane[2], frm->i_stride[2],
- img->plane[2], img->i_stride[2],
- i_width / 2, i_height / 2 );
- }
-}
-
-static void i444_to_i420( x264_frame_t *frm, x264_image_t *img,
- int i_width, int i_height )
-{
- if( img->i_csp & X264_CSP_VFLIP )
- {
- plane_copy_vflip( frm->plane[0], frm->i_stride[0],
- img->plane[0], img->i_stride[0],
- i_width, i_height );
-
- plane_subsamplehv2_vlip( frm->plane[1], frm->i_stride[1],
- img->plane[1], img->i_stride[1],
- i_width / 2, i_height / 2 );
- plane_subsamplehv2_vlip( frm->plane[2], frm->i_stride[2],
- img->plane[2], img->i_stride[2],
- i_width / 2, i_height / 2 );
- }
- else
- {
- plane_copy( frm->plane[0], frm->i_stride[0],
- img->plane[0], img->i_stride[0],
- i_width, i_height );
-
- plane_subsamplehv2( frm->plane[1], frm->i_stride[1],
- img->plane[1], img->i_stride[1],
- i_width / 2, i_height / 2 );
- plane_subsamplehv2( frm->plane[2], frm->i_stride[2],
- img->plane[2], img->i_stride[2],
- i_width / 2, i_height / 2 );
- }
-}
-static void yuyv_to_i420( x264_frame_t *frm, x264_image_t *img,
- int i_width, int i_height )
-{
- uint8_t *src = img->plane[0];
- int i_src= img->i_stride[0];
-
- uint8_t *y = frm->plane[0];
- uint8_t *u = frm->plane[1];
- uint8_t *v = frm->plane[2];
-
- if( img->i_csp & X264_CSP_VFLIP )
- {
- src += ( i_height - 1 ) * i_src;
- i_src = -i_src;
- }
-
- for( ; i_height > 0; i_height -= 2 )
- {
- uint8_t *ss = src;
- uint8_t *yy = y;
- uint8_t *uu = u;
- uint8_t *vv = v;
- int w;
-
- for( w = i_width; w > 0; w -= 2 )
- {
- *yy++ = ss[0];
- *yy++ = ss[2];
-
- *uu++ = ( ss[1] + ss[1+i_src] + 1 ) >> 1;
- *vv++ = ( ss[3] + ss[3+i_src] + 1 ) >> 1;
-
- ss += 4;
- }
- src += i_src;
- y += frm->i_stride[0];
- u += frm->i_stride[1];
- v += frm->i_stride[2];
-
- ss = src;
- yy = y;
- for( w = i_width; w > 0; w -= 2 )
- {
- *yy++ = ss[0];
- *yy++ = ss[2];
- ss += 4;
- }
- src += i_src;
- y += frm->i_stride[0];
- }
-}
-
-/* Same value than in XviD */
-#define BITS 8
-#define FIX(f) ((int)((f) * (1 << BITS) + 0.5))
-
-#define Y_R FIX(0.257)
-#define Y_G FIX(0.504)
-#define Y_B FIX(0.098)
-#define Y_ADD 16
-
-#define U_R FIX(0.148)
-#define U_G FIX(0.291)
-#define U_B FIX(0.439)
-#define U_ADD 128
-
-#define V_R FIX(0.439)
-#define V_G FIX(0.368)
-#define V_B FIX(0.071)
-#define V_ADD 128
-#define RGB_TO_I420( name, POS_R, POS_G, POS_B, S_RGB ) \
-static void name( x264_frame_t *frm, x264_image_t *img, \
- int i_width, int i_height ) \
-{ \
- uint8_t *src = img->plane[0]; \
- int i_src= img->i_stride[0]; \
- int i_y = frm->i_stride[0]; \
- uint8_t *y = frm->plane[0]; \
- uint8_t *u = frm->plane[1]; \
- uint8_t *v = frm->plane[2]; \
- \
- if( img->i_csp & X264_CSP_VFLIP ) \
- { \
- src += ( i_height - 1 ) * i_src; \
- i_src = -i_src; \
- } \
- \
- for( ; i_height > 0; i_height -= 2 ) \
- { \
- uint8_t *ss = src; \
- uint8_t *yy = y; \
- uint8_t *uu = u; \
- uint8_t *vv = v; \
- int w; \
- \
- for( w = i_width; w > 0; w -= 2 ) \
- { \
- int cr = 0,cg = 0,cb = 0; \
- int r, g, b; \
- \
- /* Luma */ \
- cr = r = ss[POS_R]; \
- cg = g = ss[POS_G]; \
- cb = b = ss[POS_B]; \
- \
- yy[0] = Y_ADD + ((Y_R * r + Y_G * g + Y_B * b) >> BITS); \
- \
- cr+= r = ss[POS_R+i_src]; \
- cg+= g = ss[POS_G+i_src]; \
- cb+= b = ss[POS_B+i_src]; \
- yy[i_y] = Y_ADD + ((Y_R * r + Y_G * g + Y_B * b) >> BITS); \
- yy++; \
- ss += S_RGB; \
- \
- cr+= r = ss[POS_R]; \
- cg+= g = ss[POS_G]; \
- cb+= b = ss[POS_B]; \
- \
- yy[0] = Y_ADD + ((Y_R * r + Y_G * g + Y_B * b) >> BITS); \
- \
- cr+= r = ss[POS_R+i_src]; \
- cg+= g = ss[POS_G+i_src]; \
- cb+= b = ss[POS_B+i_src]; \
- yy[i_y] = Y_ADD + ((Y_R * r + Y_G * g + Y_B * b) >> BITS); \
- yy++; \
- ss += S_RGB; \
- \
- /* Chroma */ \
- *uu++ = (uint8_t)(U_ADD + ((-U_R * cr - U_G * cg + U_B * cb) >> (BITS+2)) ); \
- *vv++ = (uint8_t)(V_ADD + (( V_R * cr - V_G * cg - V_B * cb) >> (BITS+2)) ); \
- } \
- \
- src += 2*i_src; \
- y += 2*frm->i_stride[0]; \
- u += frm->i_stride[1]; \
- v += frm->i_stride[2]; \
- } \
-}
-
-RGB_TO_I420( rgb_to_i420, 0, 1, 2, 3 );
-RGB_TO_I420( bgr_to_i420, 2, 1, 0, 3 );
-RGB_TO_I420( bgra_to_i420, 2, 1, 0, 4 );
-
-void x264_csp_init( int cpu, int i_csp, x264_csp_function_t *pf )
-{
- switch( i_csp )
- {
- case X264_CSP_I420:
- pf->i420 = i420_to_i420;
- pf->i422 = i422_to_i420;
- pf->i444 = i444_to_i420;
- pf->yv12 = yv12_to_i420;
- pf->yuyv = yuyv_to_i420;
- pf->rgb = rgb_to_i420;
- pf->bgr = bgr_to_i420;
- pf->bgra = bgra_to_i420;
- break;
-
- default:
- /* For now, can't happen */
- fprintf( stderr, "arg in x264_csp_init\n" );
- exit( -1 );
- break;
- }
-}
-
+++ /dev/null
-/*****************************************************************************
- * csp.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2004 Laurent Aimar
- * $Id: csp.h,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifndef _CSP_H
-#define _CSP_H 1
-
-typedef struct
-{
- void (*i420)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
- void (*i422)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
- void (*i444)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
- void (*yv12)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
- void (*yuyv)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
- void (*rgb )( x264_frame_t *, x264_image_t *, int i_width, int i_height );
- void (*bgr )( x264_frame_t *, x264_image_t *, int i_width, int i_height );
- void (*bgra)( x264_frame_t *, x264_image_t *, int i_width, int i_height );
-} x264_csp_function_t;
-
-
-void x264_csp_init( int cpu, int i_csp, x264_csp_function_t *pf );
-
-#endif
-
+++ /dev/null
-/*****************************************************************************
- * dct.c: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: dct.c,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-#include <stdarg.h>
-
-#include "x264.h"
-
-#include "dct.h"
-#ifdef HAVE_MMXEXT
-# include "i386/dct.h"
-#endif
-
-
-static inline int clip_uint8( int a )
-{
- if (a&(~255))
- return (-a)>>31;
- else
- return a;
-}
-
-/*
- * XXX For all dct dc : input could be equal to output so ...
- */
-
-static void dct2x2dc( int16_t d[2][2] )
-{
- int tmp[2][2];
-
- tmp[0][0] = d[0][0] + d[0][1];
- tmp[1][0] = d[0][0] - d[0][1];
- tmp[0][1] = d[1][0] + d[1][1];
- tmp[1][1] = d[1][0] - d[1][1];
-
- d[0][0] = tmp[0][0] + tmp[0][1];
- d[0][1] = tmp[1][0] + tmp[1][1];
- d[1][0] = tmp[0][0] - tmp[0][1];
- d[1][1] = tmp[1][0] - tmp[1][1];
-}
-
-static void dct4x4dc( int16_t d[4][4] )
-{
- int16_t tmp[4][4];
- int s01, s23;
- int d01, d23;
- int i;
-
- for( i = 0; i < 4; i++ )
- {
- s01 = d[i][0] + d[i][1];
- d01 = d[i][0] - d[i][1];
- s23 = d[i][2] + d[i][3];
- d23 = d[i][2] - d[i][3];
-
- tmp[0][i] = s01 + s23;
- tmp[1][i] = s01 - s23;
- tmp[2][i] = d01 - d23;
- tmp[3][i] = d01 + d23;
- }
-
- for( i = 0; i < 4; i++ )
- {
- s01 = tmp[i][0] + tmp[i][1];
- d01 = tmp[i][0] - tmp[i][1];
- s23 = tmp[i][2] + tmp[i][3];
- d23 = tmp[i][2] - tmp[i][3];
-
- d[0][i] = ( s01 + s23 + 1 ) >> 1;
- d[1][i] = ( s01 - s23 + 1 ) >> 1;
- d[2][i] = ( d01 - d23 + 1 ) >> 1;
- d[3][i] = ( d01 + d23 + 1 ) >> 1;
- }
-}
-
-static void idct4x4dc( int16_t d[4][4] )
-{
- int16_t tmp[4][4];
- int s01, s23;
- int d01, d23;
- int i;
-
- for( i = 0; i < 4; i++ )
- {
- s01 = d[0][i] + d[1][i];
- d01 = d[0][i] - d[1][i];
- s23 = d[2][i] + d[3][i];
- d23 = d[2][i] - d[3][i];
-
- tmp[0][i] = s01 + s23;
- tmp[1][i] = s01 - s23;
- tmp[2][i] = d01 - d23;
- tmp[3][i] = d01 + d23;
- }
-
- for( i = 0; i < 4; i++ )
- {
- s01 = tmp[i][0] + tmp[i][1];
- d01 = tmp[i][0] - tmp[i][1];
- s23 = tmp[i][2] + tmp[i][3];
- d23 = tmp[i][2] - tmp[i][3];
-
- d[i][0] = s01 + s23;
- d[i][1] = s01 - s23;
- d[i][2] = d01 - d23;
- d[i][3] = d01 + d23;
- }
-}
-
-static void sub4x4_dct( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
-{
- int16_t d[4][4];
- int16_t tmp[4][4];
- int y, x;
- int i;
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- d[y][x] = pix1[x] - pix2[x];
- }
- pix1 += i_pix1;
- pix2 += i_pix2;
- }
-
- for( i = 0; i < 4; i++ )
- {
- const int s03 = d[i][0] + d[i][3];
- const int s12 = d[i][1] + d[i][2];
- const int d03 = d[i][0] - d[i][3];
- const int d12 = d[i][1] - d[i][2];
-
- tmp[0][i] = s03 + s12;
- tmp[1][i] = 2*d03 + d12;
- tmp[2][i] = s03 - s12;
- tmp[3][i] = d03 - 2*d12;
- }
-
- for( i = 0; i < 4; i++ )
- {
- const int s03 = tmp[i][0] + tmp[i][3];
- const int s12 = tmp[i][1] + tmp[i][2];
- const int d03 = tmp[i][0] - tmp[i][3];
- const int d12 = tmp[i][1] - tmp[i][2];
-
- dct[0][i] = s03 + s12;
- dct[1][i] = 2*d03 + d12;
- dct[2][i] = s03 - s12;
- dct[3][i] = d03 - 2*d12;
- }
-}
-
-static void sub8x8_dct( int16_t dct[4][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
-{
- sub4x4_dct( dct[0], &pix1[0], i_pix1, &pix2[0], i_pix2 );
- sub4x4_dct( dct[1], &pix1[4], i_pix1, &pix2[4], i_pix2 );
- sub4x4_dct( dct[2], &pix1[4*i_pix1+0], i_pix1, &pix2[4*i_pix2+0], i_pix2 );
- sub4x4_dct( dct[3], &pix1[4*i_pix1+4], i_pix1, &pix2[4*i_pix2+4], i_pix2 );
-}
-
-static void sub16x16_dct( int16_t dct[16][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
-{
- sub8x8_dct( &dct[ 0], pix1, i_pix1, pix2, i_pix2 );
- sub8x8_dct( &dct[ 4], &pix1[8], i_pix1, &pix2[8], i_pix2 );
- sub8x8_dct( &dct[ 8], &pix1[8*i_pix1], i_pix1, &pix2[8*i_pix2], i_pix2 );
- sub8x8_dct( &dct[12], &pix1[8*i_pix1+8], i_pix1, &pix2[8*i_pix2+8], i_pix2 );
-}
-
-
-static void add4x4_idct( uint8_t *p_dst, int i_dst, int16_t dct[4][4] )
-{
- int16_t d[4][4];
- int16_t tmp[4][4];
- int x, y;
- int i;
-
- for( i = 0; i < 4; i++ )
- {
- const int s02 = dct[i][0] + dct[i][2];
- const int d02 = dct[i][0] - dct[i][2];
- const int s13 = dct[i][1] + (dct[i][3]>>1);
- const int d13 = (dct[i][1]>>1) - dct[i][3];
-
- tmp[i][0] = s02 + s13;
- tmp[i][1] = d02 + d13;
- tmp[i][2] = d02 - d13;
- tmp[i][3] = s02 - s13;
- }
-
- for( i = 0; i < 4; i++ )
- {
- const int s02 = tmp[0][i] + tmp[2][i];
- const int d02 = tmp[0][i] - tmp[2][i];
- const int s13 = tmp[1][i] + (tmp[3][i]>>1);
- const int d13 = (tmp[1][i]>>1) - tmp[3][i];
-
- d[0][i] = ( s02 + s13 + 32 ) >> 6;
- d[1][i] = ( d02 + d13 + 32 ) >> 6;
- d[2][i] = ( d02 - d13 + 32 ) >> 6;
- d[3][i] = ( s02 - s13 + 32 ) >> 6;
- }
-
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- p_dst[x] = clip_uint8( p_dst[x] + d[y][x] );
- }
- p_dst += i_dst;
- }
-}
-
-static void add8x8_idct( uint8_t *p_dst, int i_dst, int16_t dct[4][4][4] )
-{
- add4x4_idct( p_dst, i_dst, dct[0] );
- add4x4_idct( &p_dst[4], i_dst, dct[1] );
- add4x4_idct( &p_dst[4*i_dst+0], i_dst, dct[2] );
- add4x4_idct( &p_dst[4*i_dst+4], i_dst, dct[3] );
-}
-
-static void add16x16_idct( uint8_t *p_dst, int i_dst, int16_t dct[16][4][4] )
-{
- add8x8_idct( &p_dst[0], i_dst, &dct[0] );
- add8x8_idct( &p_dst[8], i_dst, &dct[4] );
- add8x8_idct( &p_dst[8*i_dst], i_dst, &dct[8] );
- add8x8_idct( &p_dst[8*i_dst+8], i_dst, &dct[12] );
-}
-
-
-
-/****************************************************************************
- * x264_dct_init:
- ****************************************************************************/
-void x264_dct_init( int cpu, x264_dct_function_t *dctf )
-{
- dctf->sub4x4_dct = sub4x4_dct;
- dctf->add4x4_idct = add4x4_idct;
-
- dctf->sub8x8_dct = sub8x8_dct;
- dctf->add8x8_idct = add8x8_idct;
-
- dctf->sub16x16_dct = sub16x16_dct;
- dctf->add16x16_idct = add16x16_idct;
-
- dctf->dct4x4dc = dct4x4dc;
- dctf->idct4x4dc = idct4x4dc;
-
- dctf->dct2x2dc = dct2x2dc;
- dctf->idct2x2dc = dct2x2dc;
-
-#ifdef HAVE_MMXEXT
- if( cpu&X264_CPU_MMXEXT )
- {
- dctf->sub4x4_dct = x264_sub4x4_dct_mmxext;
- dctf->sub8x8_dct = x264_sub8x8_dct_mmxext;
- dctf->sub16x16_dct = x264_sub16x16_dct_mmxext;
-
- dctf->add4x4_idct = x264_add4x4_idct_mmxext;
- dctf->add8x8_idct = x264_add8x8_idct_mmxext;
- dctf->add16x16_idct = x264_add16x16_idct_mmxext;
-
- dctf->dct4x4dc = x264_dct4x4dc_mmxext;
- dctf->idct4x4dc = x264_idct4x4dc_mmxext;
- }
-#endif
-}
-
+++ /dev/null
-/*****************************************************************************
- * dct.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: dct.h,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifndef _DCT_H
-#define _DCT_H 1
-
-typedef struct
-{
- void (*sub4x4_dct) ( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
- void (*add4x4_idct) ( uint8_t *p_dst, int i_dst, int16_t dct[4][4] );
-
- void (*sub8x8_dct) ( int16_t dct[4][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
- void (*add8x8_idct) ( uint8_t *p_dst, int i_dst, int16_t dct[4][4][4] );
-
- void (*sub16x16_dct) ( int16_t dct[16][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
- void (*add16x16_idct) ( uint8_t *p_dst, int i_dst, int16_t dct[16][4][4] );
-
-
- void (*dct4x4dc) ( int16_t d[4][4] );
- void (*idct4x4dc)( int16_t d[4][4] );
-
- void (*dct2x2dc) ( int16_t d[2][2] );
- void (*idct2x2dc)( int16_t d[2][2] );
-
-} x264_dct_function_t;
-
-void x264_dct_init( int cpu, x264_dct_function_t *dctf );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * frame.c: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: frame.c,v 1.1 2004/06/03 19:27:06 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 "common.h"
-#include "macroblock.h"
-
-x264_frame_t *x264_frame_new( x264_t *h )
-{
- x264_frame_t *frame = x264_malloc( sizeof( x264_frame_t ) );
- int i;
-
- int i_stride;
- int i_lines;
-
- /* allocate frame data (+64 for extra data for me) */
- i_stride = ( ( h->param.i_width + 15 )&0xfffff0 )+ 64;
- i_lines = ( ( h->param.i_height + 15 )&0xfffff0 );
-
- frame->i_plane = 3;
- for( i = 0; i < 3; i++ )
- {
- int i_divh = 1;
- int i_divw = 1;
- if( i > 0 )
- {
- if( h->param.i_csp == X264_CSP_I420 )
- i_divh = i_divw = 2;
- else if( h->param.i_csp == X264_CSP_I422 )
- i_divw = 2;
- }
- frame->i_stride[i] = i_stride / i_divw;
- frame->i_lines[i] = i_lines / i_divh;
- frame->buffer[i] = x264_malloc( frame->i_stride[i] *
- ( frame->i_lines[i] + 64 / i_divh ) );
-
- frame->plane[i] = ((uint8_t*)frame->buffer[i]) +
- frame->i_stride[i] * 32 / i_divh + 32 / i_divw;
- }
- frame->i_stride[3] = 0;
- frame->i_lines[3] = 0;
- frame->buffer[3] = NULL;
- frame->plane[3] = NULL;
-
- frame->i_poc = -1;
- frame->i_type = X264_TYPE_AUTO;
- frame->i_qpplus1 = 0;
- frame->i_pts = -1;
- frame->i_frame = -1;
-
- return frame;
-}
-
-void x264_frame_delete( x264_frame_t *frame )
-{
- int i;
- for( i = 0; i < frame->i_plane; i++ )
- {
- x264_free( frame->buffer[i] );
- }
- x264_free( frame );
-}
-
-void x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
-{
- dst->i_type = src->i_type;
- dst->i_qpplus1 = src->i_qpplus1;
- dst->i_pts = src->i_pts;
-
- switch( src->img.i_csp & X264_CSP_MASK )
- {
- case X264_CSP_I420:
- h->csp.i420( dst, &src->img, h->param.i_width, h->param.i_height );
- break;
- case X264_CSP_YV12:
- h->csp.yv12( dst, &src->img, h->param.i_width, h->param.i_height );
- break;
- case X264_CSP_I422:
- h->csp.i422( dst, &src->img, h->param.i_width, h->param.i_height );
- break;
- case X264_CSP_I444:
- h->csp.i444( dst, &src->img, h->param.i_width, h->param.i_height );
- break;
- case X264_CSP_YUYV:
- h->csp.yuyv( dst, &src->img, h->param.i_width, h->param.i_height );
- break;
- case X264_CSP_RGB:
- h->csp.rgb( dst, &src->img, h->param.i_width, h->param.i_height );
- break;
- case X264_CSP_BGR:
- h->csp.bgr( dst, &src->img, h->param.i_width, h->param.i_height );
- break;
- case X264_CSP_BGRA:
- h->csp.bgra( dst, &src->img, h->param.i_width, h->param.i_height );
- break;
-
- default:
- x264_log( h, X264_LOG_ERROR, "Arg invalid CSP\n" );
- break;
- }
-}
-
-
-
-void x264_frame_expand_border( x264_frame_t *frame )
-{
- int w;
- int i, y;
- for( i = 0; i < frame->i_plane; i++ )
- {
-#define PPIXEL(x, y) ( frame->plane[i] + (x) +(y)*frame->i_stride[i] )
- w = ( i == 0 ) ? 32 : 16;
-
- for( y = 0; y < w; y++ )
- {
- /* upper band */
- memcpy( PPIXEL(0,-y-1), PPIXEL(0,0), frame->i_stride[i] - 2 * w);
- /* up left corner */
- memset( PPIXEL(-w,-y-1 ), PPIXEL(0,0)[0], w );
- /* up right corner */
- memset( PPIXEL(frame->i_stride[i] - 2*w,-y-1), PPIXEL( frame->i_stride[i]-1-2*w,0)[0], w );
-
- /* lower band */
- memcpy( PPIXEL(0, frame->i_lines[i]+y), PPIXEL(0,frame->i_lines[i]-1), frame->i_stride[i] - 2 * w );
- /* low left corner */
- memset( PPIXEL(-w, frame->i_lines[i]+y), PPIXEL(0,frame->i_lines[i]-1)[0], w);
- /* low right corner */
- memset( PPIXEL(frame->i_stride[i]-2*w, frame->i_lines[i]+y), PPIXEL(frame->i_stride[i]-1-2*w,frame->i_lines[i]-1)[0], w);
-
- }
- for( y = 0; y < frame->i_lines[i]; y++ )
- {
- /* left band */
- memset( PPIXEL( -w, y ), PPIXEL( 0, y )[0], w );
- /* right band */
- memset( PPIXEL( frame->i_stride[i]-2*w, y ), PPIXEL( frame->i_stride[i] - 1-2*w, y )[0], w );
- }
-#undef PPIXEL
- }
-}
-
-/* FIXME theses tables are duplicated with the ones in macroblock.c */
-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 i_chroma_qp_table[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
-};
-
-/* Deblocking filter (p153) */
-static const int i_alpha_table[52] =
-{
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 4, 4, 5, 6,
- 7, 8, 9, 10, 12, 13, 15, 17, 20, 22,
- 25, 28, 32, 36, 40, 45, 50, 56, 63, 71,
- 80, 90,101,113,127,144,162,182,203,226,
- 255, 255
-};
-static const int i_beta_table[52] =
-{
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 2, 2, 2, 3,
- 3, 3, 3, 4, 4, 4, 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
-};
-static const int i_tc0_table[52][3] =
-{
- { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
- { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
- { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 1 },
- { 0, 0, 1 }, { 0, 0, 1 }, { 0, 0, 1 }, { 0, 1, 1 }, { 0, 1, 1 }, { 1, 1, 1 },
- { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 2 }, { 1, 1, 2 },
- { 1, 1, 2 }, { 1, 2, 3 }, { 1, 2, 3 }, { 2, 2, 3 }, { 2, 2, 4 }, { 2, 3, 4 },
- { 2, 3, 4 }, { 3, 3, 5 }, { 3, 4, 6 }, { 3, 4, 6 }, { 4, 5, 7 }, { 4, 5, 8 },
- { 4, 6, 9 }, { 5, 7,10 }, { 6, 8,11 }, { 6, 8,13 }, { 7,10,14 }, { 8,11,16 },
- { 9,12,18 }, {10,13,20 }, {11,15,23 }, {13,17,25 }
-};
-
-/* From ffmpeg */
-static inline int clip_uint8( int a )
-{
- if (a&(~255))
- return (-a)>>31;
- else
- return a;
-}
-
-static inline void deblocking_filter_edgev( x264_t *h, uint8_t *pix, int i_pix_stride, int bS[4], int i_QP )
-{
- int i, d;
- const int i_index_a = x264_clip3( i_QP + h->sh.i_alpha_c0_offset, 0, 51 );
- const int alpha = i_alpha_table[i_index_a];
- const int beta = i_beta_table[x264_clip3( i_QP + h->sh.i_beta_offset, 0, 51 )];
-
- for( i = 0; i < 4; i++ )
- {
- if( bS[i] == 0 )
- {
- pix += 4 * i_pix_stride;
- continue;
- }
-
- if( bS[i] < 4 )
- {
- const int tc0 = i_tc0_table[i_index_a][bS[i] - 1];
-
- /* 4px edge length */
- for( d = 0; d < 4; d++ )
- {
- const int p0 = pix[-1];
- const int p1 = pix[-2];
- const int p2 = pix[-3];
- const int q0 = pix[0];
- const int q1 = pix[1];
- const int q2 = pix[2];
-
- if( abs( p0 - q0 ) < alpha &&
- abs( p1 - p0 ) < beta &&
- abs( q1 - q0 ) < beta )
- {
- int tc = tc0;
- int i_delta;
-
- if( abs( p2 - p0 ) < beta )
- {
- pix[-2] = p1 + x264_clip3( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
- tc++;
- }
- if( abs( q2 - q0 ) < beta )
- {
- pix[1] = q1 + x264_clip3( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
- tc++;
- }
-
- i_delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
- pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */
- pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
- }
- pix += i_pix_stride;
- }
- }
- else
- {
- /* 4px edge length */
- for( d = 0; d < 4; d++ )
- {
- const int p0 = pix[-1];
- const int p1 = pix[-2];
- const int p2 = pix[-3];
-
- const int q0 = pix[0];
- const int q1 = pix[1];
- const int q2 = pix[2];
-
- if( abs( p0 - q0 ) < alpha &&
- abs( p1 - p0 ) < beta &&
- abs( q1 - q0 ) < beta )
- {
- if( abs( p0 - q0 ) < (( alpha >> 2 ) + 2 ) )
- {
- if( abs( p2 - p0 ) < beta )
- {
- const int p3 = pix[-4];
- /* p0', p1', p2' */
- pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
- pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
- pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
- }
- else
- {
- /* p0' */
- pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
- }
- if( abs( q2 - q0 ) < beta )
- {
- const int q3 = pix[3];
- /* q0', q1', q2' */
- pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
- pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
- pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
- }
- else
- {
- /* q0' */
- pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
- }
- }
- else
- {
- /* p0', q0' */
- pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
- pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
- }
- }
- pix += i_pix_stride;
- }
- }
- }
-}
-
-static inline void deblocking_filter_edgecv( x264_t *h, uint8_t *pix, int i_pix_stride, int bS[4], int i_QP )
-{
- int i, d;
- const int i_index_a = x264_clip3( i_QP + h->sh.i_alpha_c0_offset, 0, 51 );
- const int alpha = i_alpha_table[i_index_a];
- const int beta = i_beta_table[x264_clip3( i_QP + h->sh.i_beta_offset, 0, 51 )];
-
- for( i = 0; i < 4; i++ )
- {
- if( bS[i] == 0 )
- {
- pix += 2 * i_pix_stride;
- continue;
- }
-
- if( bS[i] < 4 )
- {
- const int tc = i_tc0_table[i_index_a][bS[i] - 1] + 1;
- /* 2px edge length (because we use same bS than the one for luma) */
- for( d = 0; d < 2; d++ )
- {
- const int p0 = pix[-1];
- const int p1 = pix[-2];
- const int q0 = pix[0];
- const int q1 = pix[1];
-
- if( abs( p0 - q0 ) < alpha &&
- abs( p1 - p0 ) < beta &&
- abs( q1 - q0 ) < beta )
- {
- const int i_delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
-
- pix[-1] = clip_uint8( p0 + i_delta ); /* p0' */
- pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
- }
- pix += i_pix_stride;
- }
- }
- else
- {
- /* 2px edge length (because we use same bS than the one for luma) */
- for( d = 0; d < 2; d++ )
- {
- const int p0 = pix[-1];
- const int p1 = pix[-2];
- const int q0 = pix[0];
- const int q1 = pix[1];
-
- if( abs( p0 - q0 ) < alpha &&
- abs( p1 - p0 ) < beta &&
- abs( q1 - q0 ) < beta )
- {
- pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
- pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
- }
- pix += i_pix_stride;
- }
- }
- }
-}
-
-static inline void deblocking_filter_edgeh( x264_t *h, uint8_t *pix, int i_pix_stride, int bS[4], int i_QP )
-{
- int i, d;
- const int i_index_a = x264_clip3( i_QP + h->sh.i_alpha_c0_offset, 0, 51 );
- const int alpha = i_alpha_table[i_index_a];
- const int beta = i_beta_table[x264_clip3( i_QP + h->sh.i_beta_offset, 0, 51 )];
-
- int i_pix_next = i_pix_stride;
-
- for( i = 0; i < 4; i++ )
- {
- if( bS[i] == 0 )
- {
- pix += 4;
- continue;
- }
-
- if( bS[i] < 4 )
- {
- const int tc0 = i_tc0_table[i_index_a][bS[i] - 1];
- /* 4px edge length */
- for( d = 0; d < 4; d++ )
- {
- const int p0 = pix[-i_pix_next];
- const int p1 = pix[-2*i_pix_next];
- const int p2 = pix[-3*i_pix_next];
- const int q0 = pix[0];
- const int q1 = pix[1*i_pix_next];
- const int q2 = pix[2*i_pix_next];
-
- if( abs( p0 - q0 ) < alpha &&
- abs( p1 - p0 ) < beta &&
- abs( q1 - q0 ) < beta )
- {
- int tc = tc0;
- int i_delta;
-
- if( abs( p2 - p0 ) < beta )
- {
- pix[-2*i_pix_next] = p1 + x264_clip3( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
- tc++;
- }
- if( abs( q2 - q0 ) < beta )
- {
- pix[i_pix_next] = q1 + x264_clip3( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
- tc++;
- }
-
- i_delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
- pix[-i_pix_next] = clip_uint8( p0 + i_delta ); /* p0' */
- pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
- }
- pix++;
- }
- }
- else
- {
- /* 4px edge length */
- for( d = 0; d < 4; d++ )
- {
- const int p0 = pix[-i_pix_next];
- const int p1 = pix[-2*i_pix_next];
- const int p2 = pix[-3*i_pix_next];
- const int q0 = pix[0];
- const int q1 = pix[1*i_pix_next];
- const int q2 = pix[2*i_pix_next];
-
- if( abs( p0 - q0 ) < alpha &&
- abs( p1 - p0 ) < beta &&
- abs( q1 - q0 ) < beta )
- {
- const int p3 = pix[-4*i_pix_next];
- const int q3 = pix[ 3*i_pix_next];
-
- if( abs( p0 - q0 ) < (( alpha >> 2 ) + 2 ) )
- {
- if( abs( p2 - p0 ) < beta )
- {
- /* p0', p1', p2' */
- pix[-1*i_pix_next] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
- pix[-2*i_pix_next] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
- pix[-3*i_pix_next] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
- }
- else
- {
- /* p0' */
- pix[-1*i_pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
- }
- if( abs( q2 - q0 ) < beta )
- {
- /* q0', q1', q2' */
- pix[0*i_pix_next] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
- pix[1*i_pix_next] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
- pix[2*i_pix_next] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
- }
- else
- {
- /* q0' */
- pix[0*i_pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
- }
- }
- else
- {
- /* p0' */
- pix[-1*i_pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
- /* q0' */
- pix[0*i_pix_next] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
- }
- }
- pix++;
- }
-
- }
- }
-}
-
-static inline void deblocking_filter_edgech( x264_t *h, uint8_t *pix, int i_pix_stride, int bS[4], int i_QP )
-{
- int i, d;
- const int i_index_a = x264_clip3( i_QP + h->sh.i_alpha_c0_offset, 0, 51 );
- const int alpha = i_alpha_table[i_index_a];
- const int beta = i_beta_table[x264_clip3( i_QP + h->sh.i_beta_offset, 0, 51 )];
-
- int i_pix_next = i_pix_stride;
-
- for( i = 0; i < 4; i++ )
- {
- if( bS[i] == 0 )
- {
- pix += 2;
- continue;
- }
- if( bS[i] < 4 )
- {
- int tc = i_tc0_table[i_index_a][bS[i] - 1] + 1;
- /* 2px edge length (see deblocking_filter_edgecv) */
- for( d = 0; d < 2; d++ )
- {
- const int p0 = pix[-1*i_pix_next];
- const int p1 = pix[-2*i_pix_next];
- const int q0 = pix[0];
- const int q1 = pix[1*i_pix_next];
-
- if( abs( p0 - q0 ) < alpha &&
- abs( p1 - p0 ) < beta &&
- abs( q1 - q0 ) < beta )
- {
- int i_delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
-
- pix[-i_pix_next] = clip_uint8( p0 + i_delta ); /* p0' */
- pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
- }
- pix++;
- }
- }
- else
- {
- /* 2px edge length (see deblocking_filter_edgecv) */
- for( d = 0; d < 2; d++ )
- {
- const int p0 = pix[-1*i_pix_next];
- const int p1 = pix[-2*i_pix_next];
- const int q0 = pix[0];
- const int q1 = pix[1*i_pix_next];
-
- if( abs( p0 - q0 ) < alpha &&
- abs( p1 - p0 ) < beta &&
- abs( q1 - q0 ) < beta )
- {
- pix[-i_pix_next] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
- pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
- }
- pix++;
- }
- }
- }
-}
-
-void x264_frame_deblocking_filter( x264_t *h, int i_slice_type )
-{
- const int s8x8 = 2 * h->mb.i_mb_stride;
- const int s4x4 = 4 * h->mb.i_mb_stride;
-
- int mb_y, mb_x;
-
- for( mb_y = 0, mb_x = 0; mb_y < h->sps->i_mb_height; )
- {
- const int mb_xy = mb_y * h->mb.i_mb_stride + mb_x;
- const int mb_8x8 = 2 * s8x8 * mb_y + 2 * mb_x;
- const int mb_4x4 = 4 * s4x4 * mb_y + 4 * mb_x;
- int i_edge;
- int i_dir;
-
- /* i_dir == 0 -> vertical edge
- * i_dir == 1 -> horizontal edge */
- for( i_dir = 0; i_dir < 2; i_dir++ )
- {
- int i_start;
- int i_qp, i_qpn;
-
- i_start = (( i_dir == 0 && mb_x != 0 ) || ( i_dir == 1 && mb_y != 0 ) ) ? 0 : 1;
-
- for( i_edge = i_start; i_edge < 4; i_edge++ )
- {
- int mbn_xy = i_edge > 0 ? mb_xy : ( i_dir == 0 ? mb_xy - 1 : mb_xy - h->mb.i_mb_stride );
- int mbn_8x8 = i_edge > 0 ? mb_8x8 : ( i_dir == 0 ? mb_8x8 - 2 : mb_8x8 - 2 * s8x8 );
- int mbn_4x4 = i_edge > 0 ? mb_4x4 : ( i_dir == 0 ? mb_4x4 - 4 : mb_4x4 - 4 * s4x4 );
-
- int bS[4]; /* filtering strength */
-
- /* *** Get bS for each 4px for the current edge *** */
- if( IS_INTRA( h->mb.type[mb_xy] ) || IS_INTRA( h->mb.type[mbn_xy] ) )
- {
- bS[0] = bS[1] = bS[2] = bS[3] = ( i_edge == 0 ? 4 : 3 );
- }
- else
- {
- int i;
- for( i = 0; i < 4; i++ )
- {
- int x = i_dir == 0 ? i_edge : i;
- int y = i_dir == 0 ? i : i_edge;
- int xn = (x - (i_dir == 0 ? 1 : 0 ))&0x03;
- int yn = (y - (i_dir == 0 ? 0 : 1 ))&0x03;
-
- if( h->mb.non_zero_count[mb_xy][block_idx_xy[x][y]] != 0 ||
- h->mb.non_zero_count[mbn_xy][block_idx_xy[xn][yn]] != 0 )
- {
- bS[i] = 2;
- }
- else if( i_slice_type == SLICE_TYPE_P )
- {
- if( h->mb.ref[0][mb_8x8+(x/2)+(y/2)*s8x8] != h->mb.ref[0][mbn_8x8+(xn/2)+(yn/2)*s8x8] ||
- abs( h->mb.mv[0][mb_4x4+x+y*s4x4][0] - h->mb.mv[0][mbn_4x4+xn+yn*s4x4][0] ) >= 4 ||
- abs( h->mb.mv[0][mb_4x4+x+y*s4x4][1] - h->mb.mv[0][mbn_4x4+xn+yn*s4x4][1] ) >= 4 )
- {
- bS[i] = 1;
- }
- else
- {
- bS[i] = 0;
- }
- }
- else
- {
- /* FIXME */
- x264_log( h, X264_LOG_ERROR, "deblocking filter doesn't work yet with B slice\n" );
- return;
- }
- }
- }
-
- /* *** filter *** */
- /* Y plane */
- i_qp = h->mb.qp[mb_xy];
- i_qpn= h->mb.qp[mbn_xy];
-
- if( i_dir == 0 )
- {
- /* vertical edge */
- deblocking_filter_edgev( h, &h->fdec->plane[0][16 * mb_y * h->fdec->i_stride[0]+ 16 * mb_x + 4 * i_edge],
- h->fdec->i_stride[0], bS, (i_qp+i_qpn+1) >> 1);
- if( (i_edge % 2) == 0 )
- {
- /* U/V planes */
- int i_qpc = ( i_chroma_qp_table[x264_clip3( i_qp + h->pps->i_chroma_qp_index_offset, 0, 51 )] +
- i_chroma_qp_table[x264_clip3( i_qpn + h->pps->i_chroma_qp_index_offset, 0, 51 )] + 1 ) >> 1;
- deblocking_filter_edgecv( h, &h->fdec->plane[1][8*(mb_y*h->fdec->i_stride[1]+mb_x)+i_edge*2],
- h->fdec->i_stride[1], bS, i_qpc );
- deblocking_filter_edgecv( h, &h->fdec->plane[2][8*(mb_y*h->fdec->i_stride[2]+mb_x)+i_edge*2],
- h->fdec->i_stride[2], bS, i_qpc );
- }
- }
- else
- {
- /* horizontal edge */
- deblocking_filter_edgeh( h, &h->fdec->plane[0][(16*mb_y + 4 * i_edge) * h->fdec->i_stride[0]+ 16 * mb_x],
- h->fdec->i_stride[0], bS, (i_qp+i_qpn+1) >> 1 );
- /* U/V planes */
- if( ( i_edge % 2 ) == 0 )
- {
- int i_qpc = ( i_chroma_qp_table[x264_clip3( i_qp + h->pps->i_chroma_qp_index_offset, 0, 51 )] +
- i_chroma_qp_table[x264_clip3( i_qpn + h->pps->i_chroma_qp_index_offset, 0, 51 )] + 1 ) >> 1;
- deblocking_filter_edgech( h, &h->fdec->plane[1][8*(mb_y*h->fdec->i_stride[1]+mb_x)+i_edge*2*h->fdec->i_stride[1]],
- h->fdec->i_stride[1], bS, i_qpc );
- deblocking_filter_edgech( h, &h->fdec->plane[2][8*(mb_y*h->fdec->i_stride[2]+mb_x)+i_edge*2*h->fdec->i_stride[2]],
- h->fdec->i_stride[2], bS, i_qpc );
- }
- }
- }
- }
-
- /* newt mb */
- mb_x++;
- if( mb_x >= h->sps->i_mb_width )
- {
- mb_x = 0;
- mb_y++;
- }
- }
-}
-
-
-
-
+++ /dev/null
-/*****************************************************************************
- * frame.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: frame.h,v 1.1 2004/06/03 19:27:06 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.
- *****************************************************************************/
-
-#ifndef _FRAME_H
-#define _FRAME_H 1
-
-typedef struct
-{
- /* */
- int i_poc;
- int i_type;
- int i_qpplus1;
- int64_t i_pts;
- int i_frame; /* Presentation frame number */
-
- /* YUV buffer */
- int i_plane;
- int i_stride[4];
- int i_lines[4];
- uint8_t *plane[4];
-
- /* for unrestricted mv we allocate more data than needed
- * allocated data are stored in buffer */
- void *buffer[4];
-
-} x264_frame_t;
-
-x264_frame_t *x264_frame_new( x264_t *h );
-void x264_frame_delete( x264_frame_t *frame );
-
-void x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src );
-
-void x264_frame_expand_border( x264_frame_t *frame );
-
-void x264_frame_deblocking_filter( x264_t *h, int i_slice_type );
-
-#endif
+++ /dev/null
-;*****************************************************************************
-;* cpu.asm: h264 encoder library
-;*****************************************************************************
-;* Copyright (C) 2003 x264 project
-;* $Id: cpu.asm,v 1.1 2004/06/03 19:27:07 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.
-;*****************************************************************************
-
-BITS 32
-
-;=============================================================================
-; Macros and other preprocessor constants
-;=============================================================================
-
-%macro cglobal 1
- %ifdef PREFIX
- global _%1
- %define %1 _%1
- %else
- global %1
- %endif
-%endmacro
-
-;=============================================================================
-; Code
-;=============================================================================
-
-SECTION .text
-
-cglobal x264_cpu_cpuid_test
-cglobal x264_cpu_cpuid
-cglobal x264_emms
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_cpu_cpuid_test( void ) return 0 if unsupported
-;-----------------------------------------------------------------------------
-x264_cpu_cpuid_test:
- pushfd
- push ebx
- push ebp
- push esi
- push edi
-
- pushfd
- pop eax
- mov ebx, eax
- xor eax, 0x200000
- push eax
- popfd
- pushfd
- pop eax
- xor eax, ebx
-
- pop edi
- pop esi
- pop ebp
- pop ebx
- popfd
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
-;-----------------------------------------------------------------------------
-x264_cpu_cpuid:
-
- push ebp
- mov ebp, esp
- push ebx
- push esi
- push edi
-
- mov eax, [ebp + 8]
- cpuid
-
- mov esi, [ebp + 12]
- mov [esi], eax
-
- mov esi, [ebp + 16]
- mov [esi], ebx
-
- mov esi, [ebp + 20]
- mov [esi], ecx
-
- mov esi, [ebp + 24]
- mov [esi], edx
-
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void __cdecl x264_emms( void )
-;-----------------------------------------------------------------------------
-x264_emms:
- emms
- ret
-
+++ /dev/null
-/*****************************************************************************
- * dct.c: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: dct-c.c,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-#include <stdarg.h>
-
-#include "x264.h"
-
-#include "../dct.h"
-#include "dct.h"
-
-
-#if 0
-#define MMX_ZERO( MMZ ) \
- asm volatile( "pxor " #MMZ ", " #MMZ "\n" :: )
-
-/* MMP : diff, MMT: temp */
-#define MMX_LOAD_DIFF_4P( MMP, MMT, MMZ, pix1, pix2 ) \
- asm volatile( "movd (%0), " #MMP "\n" \
- "punpcklbw " #MMZ ", " #MMP "\n" \
- "movd (%1), " #MMT "\n" \
- "punpcklbw " #MMZ ", " #MMT "\n" \
- "psubw " #MMT ", " #MMP "\n" : : "r"(pix1), "r"(pix2) )
-
-/* in: out: mma=mma+mmb, mmb=mmb-mma */
-#define MMX_SUMSUB_BA( MMA, MMB ) \
- asm volatile( "paddw " #MMB ", " #MMA "\n"\
- "paddw " #MMB ", " #MMB "\n"\
- "psubw " #MMA ", " #MMB "\n" :: )
-
-#define MMX_SUMSUB_BADC( MMA, MMB, MMC, MMD ) \
- asm volatile( "paddw " #MMB ", " #MMA "\n"\
- "paddw " #MMD ", " #MMC "\n"\
- "paddw " #MMB ", " #MMB "\n"\
- "paddw " #MMD ", " #MMD "\n"\
- "psubw " #MMA ", " #MMB "\n"\
- "psubw " #MMC ", " #MMD "\n" :: )
-
-/* inputs MMA, MMB output MMA MMT */
-#define MMX_SUMSUB2_AB( MMA, MMB, MMT ) \
- asm volatile( "movq " #MMA ", " #MMT "\n" \
- "paddw " #MMA ", " #MMA "\n" \
- "paddw " #MMB ", " #MMA "\n" \
- "psubw " #MMB ", " #MMT "\n" \
- "psubw " #MMB ", " #MMT "\n" :: )
-
-/* inputs MMA, MMB output MMA MMS */
-#define MMX_SUMSUBD2_AB( MMA, MMB, MMT, MMS ) \
- asm volatile( "movq " #MMA ", " #MMS "\n" \
- "movq " #MMB ", " #MMT "\n" \
- "psraw $1 , " #MMB "\n" \
- "psraw $1 , " #MMS "\n" \
- "paddw " #MMB ", " #MMA "\n" \
- "psubw " #MMT ", " #MMS "\n" :: )
-
-#define SBUTTERFLYwd(a,b,t )\
- asm volatile( "movq " #a ", " #t " \n\t" \
- "punpcklwd " #b ", " #a " \n\t" \
- "punpckhwd " #b ", " #t " \n\t" :: )
-
-#define SBUTTERFLYdq(a,b,t )\
- asm volatile( "movq " #a ", " #t " \n\t" \
- "punpckldq " #b ", " #a " \n\t" \
- "punpckhdq " #b ", " #t " \n\t" :: )
-
-/* input ABCD output ADTC */
-#define MMX_TRANSPOSE( MMA, MMB, MMC, MMD, MMT ) \
- SBUTTERFLYwd( MMA, MMB, MMT ); \
- SBUTTERFLYwd( MMC, MMD, MMB ); \
- SBUTTERFLYdq( MMA, MMC, MMD ); \
- SBUTTERFLYdq( MMT, MMB, MMC )
-
-#define MMX_STORE_DIFF_4P( MMP, MMT, MM32, MMZ, dst ) \
- asm volatile( "paddw " #MM32 "," #MMP "\n" \
- "psraw $6, " #MMP "\n" \
- "movd (%0), " #MMT "\n" \
- "punpcklbw " #MMZ ", " #MMT "\n" \
- "paddsw " #MMT ", " #MMP "\n" \
- "packuswb " #MMZ ", " #MMP "\n" \
- "movd " #MMP ", (%0)\n" :: "r"(dst) )
-
-#define UNUSED_LONGLONG( foo ) \
- static const unsigned long long foo __asm__ (#foo) __attribute__((unused)) __attribute__((aligned(16)))
-
-UNUSED_LONGLONG( x264_mmx_32 ) = 0x0020002000200020ULL;
-UNUSED_LONGLONG( x264_mmx_1 ) = 0x0001000100010001ULL;
-
-
-/*
- * XXX For all dct dc : input could be equal to output so ...
- */
-void x264_dct4x4dc_mmxext( int16_t d[4][4] )
-{
- /* load DCT */
- asm volatile(
- "movq (%0), %%mm0\n"
- "movq 8(%0), %%mm1\n"
- "movq 16(%0), %%mm2\n"
- "movq 24(%0), %%mm3\n" :: "r"(d) );
-
- MMX_SUMSUB_BADC( %%mm1, %%mm0, %%mm3, %%mm2 ); /* mm1=s01 mm0=d01 mm3=s23 mm2=d23 */
- MMX_SUMSUB_BADC( %%mm3, %%mm1, %%mm2, %%mm0 ); /* mm3=s01+s23 mm1=s01-s23 mm2=d01+d23 mm0=d01-d23 */
-
- /* in: mm3, mm1, mm0, mm2 out: mm3, mm2, mm4, mm0 */
- MMX_TRANSPOSE ( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 );
-
- MMX_SUMSUB_BADC( %%mm2, %%mm3, %%mm0, %%mm4 ); /* mm2=s01 mm3=d01 mm0=s23 mm4=d23 */
- MMX_SUMSUB_BADC( %%mm0, %%mm2, %%mm4, %%mm3 ); /* mm0=s01+s23 mm2=s01-s23 mm4=d01+d23 mm3=d01-d23 */
-
- /* in: mm0, mm2, mm3, mm4 out: mm0, mm4, mm1, mm3 */
- MMX_TRANSPOSE ( %%mm0, %%mm2, %%mm3, %%mm4, %%mm1 );
-
-
- asm volatile( "movq x264_mmx_1, %%mm6" :: );
-
- /* Store back */
- asm volatile(
- "paddw %%mm6, %%mm0\n"
- "paddw %%mm6, %%mm4\n"
-
- "psraw $1, %%mm0\n"
- "movq %%mm0, (%0)\n"
- "psraw $1, %%mm4\n"
- "movq %%mm4, 8(%0)\n"
-
- "paddw %%mm6, %%mm1\n"
- "paddw %%mm6, %%mm3\n"
-
- "psraw $1, %%mm1\n"
- "movq %%mm1, 16(%0)\n"
- "psraw $1, %%mm3\n"
- "movq %%mm3, 24(%0)\n" :: "r"(d) );
-}
-
-void x264_idct4x4dc_mmxext( int16_t d[4][4] )
-{
- /* load DCT */
- asm volatile(
- "movq (%0), %%mm0\n"
- "movq 8(%0), %%mm1\n"
- "movq 16(%0), %%mm2\n"
- "movq 24(%0), %%mm3\n" :: "r"(d) );
-
- MMX_SUMSUB_BADC( %%mm1, %%mm0, %%mm3, %%mm2 ); /* mm1=s01 mm0=d01 mm3=s23 mm2=d23 */
- MMX_SUMSUB_BADC( %%mm3, %%mm1, %%mm2, %%mm0 ); /* mm3=s01+s23 mm1=s01-s23 mm2=d01+d23 mm0=d01-d23 */
-
- /* in: mm3, mm1, mm0, mm2 out: mm3, mm2, mm4, mm0 */
- MMX_TRANSPOSE( %%mm3, %%mm1, %%mm0, %%mm2, %%mm4 );
-
- MMX_SUMSUB_BADC( %%mm2, %%mm3, %%mm0, %%mm4 ); /* mm2=s01 mm3=d01 mm0=s23 mm4=d23 */
- MMX_SUMSUB_BADC( %%mm0, %%mm2, %%mm4, %%mm3 ); /* mm0=s01+s23 mm2=s01-s23 mm4=d01+d23 mm3=d01-d23 */
-
- /* in: mm0, mm2, mm3, mm4 out: mm0, mm4, mm1, mm3 */
- MMX_TRANSPOSE( %%mm0, %%mm2, %%mm3, %%mm4, %%mm1 );
-
- /* Store back */
- asm volatile(
- "movq %%mm0, (%0)\n"
- "movq %%mm4, 8(%0)\n"
- "movq %%mm1, 16(%0)\n"
- "movq %%mm3, 24(%0)\n" :: "r"(d) );
-}
-
-/****************************************************************************
- * subXxX_dct:
- ****************************************************************************/
-inline void x264_sub4x4_dct_mmxext( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
-{
- /* Reset mm7 */
- MMX_ZERO( %%mm7 );
-
- /* Load 4 lines */
- MMX_LOAD_DIFF_4P( %%mm0, %%mm6, %%mm7, &pix1[0*i_pix1], &pix2[0*i_pix2] );
- MMX_LOAD_DIFF_4P( %%mm1, %%mm6, %%mm7, &pix1[1*i_pix1], &pix2[1*i_pix2] );
- MMX_LOAD_DIFF_4P( %%mm2, %%mm6, %%mm7, &pix1[2*i_pix1], &pix2[2*i_pix2] );
- MMX_LOAD_DIFF_4P( %%mm3, %%mm6, %%mm7, &pix1[3*i_pix1], &pix2[3*i_pix2] );
-
- MMX_SUMSUB_BADC( %%mm3, %%mm0, %%mm2, %%mm1 ); /* mm3=s03 mm0=d03 mm2=s12 mm1=d12 */
-
- MMX_SUMSUB_BA( %%mm2, %%mm3 ); /* mm2=s03+s12 mm3=s03-s12 */
- MMX_SUMSUB2_AB( %%mm0, %%mm1, %%mm4 ); /* mm0=2.d03+d12 mm4=d03-2.d12 */
-
- /* transpose in: mm2, mm0, mm3, mm4, out: mm2, mm4, mm1, mm3 */
- MMX_TRANSPOSE( %%mm2, %%mm0, %%mm3, %%mm4, %%mm1 );
-
- MMX_SUMSUB_BADC( %%mm3, %%mm2, %%mm1, %%mm4 ); /* mm3=s03 mm2=d03 mm1=s12 mm4=d12 */
-
- MMX_SUMSUB_BA( %%mm1, %%mm3 ); /* mm1=s03+s12 mm3=s03-s12 */
- MMX_SUMSUB2_AB( %%mm2, %%mm4, %%mm0 ); /* mm2=2.d03+d12 mm0=d03-2.d12 */
-
- /* transpose in: mm1, mm2, mm3, mm0, out: mm1, mm0, mm4, mm3 */
- MMX_TRANSPOSE( %%mm1, %%mm2, %%mm3, %%mm0, %%mm4 );
-
- /* Store back */
- asm volatile(
- "movq %%mm1, (%0)\n"
- "movq %%mm0, 8(%0)\n"
- "movq %%mm4, 16(%0)\n"
- "movq %%mm3, 24(%0)\n" :: "r"(dct) );
-}
-#endif
-
-void x264_sub8x8_dct_mmxext( int16_t dct[4][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
-{
- x264_sub4x4_dct_mmxext( dct[0], &pix1[0], i_pix1, &pix2[0], i_pix2 );
- x264_sub4x4_dct_mmxext( dct[1], &pix1[4], i_pix1, &pix2[4], i_pix2 );
- x264_sub4x4_dct_mmxext( dct[2], &pix1[4*i_pix1+0], i_pix1, &pix2[4*i_pix2+0], i_pix2 );
- x264_sub4x4_dct_mmxext( dct[3], &pix1[4*i_pix1+4], i_pix1, &pix2[4*i_pix2+4], i_pix2 );
-}
-
-void x264_sub16x16_dct_mmxext( int16_t dct[16][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
-{
- x264_sub8x8_dct_mmxext( &dct[ 0], &pix1[0], i_pix1, &pix2[0], i_pix2 );
- x264_sub8x8_dct_mmxext( &dct[ 4], &pix1[8], i_pix1, &pix2[8], i_pix2 );
- x264_sub8x8_dct_mmxext( &dct[ 8], &pix1[8*i_pix1], i_pix1, &pix2[8*i_pix2], i_pix2 );
- x264_sub8x8_dct_mmxext( &dct[12], &pix1[8*i_pix1+8], i_pix1, &pix2[8*i_pix2+8], i_pix2 );
-}
-
-
-
-/****************************************************************************
- * addXxX_idct:
- ****************************************************************************/
-#if 0
-inline void x264_add4x4_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4] )
-{
- /* Load dct coeffs */
- asm volatile(
- "movq (%0), %%mm0\n"
- "movq 8(%0), %%mm1\n"
- "movq 16(%0), %%mm2\n"
- "movq 24(%0), %%mm3\n" :: "r"(dct) );
-
- MMX_SUMSUB_BA ( %%mm2, %%mm0 ); /* mm2=s02 mm0=d02 */
- MMX_SUMSUBD2_AB( %%mm1, %%mm3, %%mm5, %%mm4 ); /* mm1=s13 mm4=d13 ( well 1 + 3>>1 and 1>>1 + 3) */
-
- MMX_SUMSUB_BADC( %%mm1, %%mm2, %%mm4, %%mm0 ); /* mm1=s02+s13 mm2=s02-s13 mm4=d02+d13 mm0=d02-d13 */
-
- /* in: mm1, mm4, mm0, mm2 out: mm1, mm2, mm3, mm0 */
- MMX_TRANSPOSE ( %%mm1, %%mm4, %%mm0, %%mm2, %%mm3 );
-
- MMX_SUMSUB_BA ( %%mm3, %%mm1 ); /* mm3=s02 mm1=d02 */
- MMX_SUMSUBD2_AB( %%mm2, %%mm0, %%mm5, %%mm4 ); /* mm2=s13 mm4=d13 ( well 1 + 3>>1 and 1>>1 + 3) */
-
- MMX_SUMSUB_BADC( %%mm2, %%mm3, %%mm4, %%mm1 ); /* mm2=s02+s13 mm3=s02-s13 mm4=d02+d13 mm1=d02-d13 */
-
- /* in: mm2, mm4, mm1, mm3 out: mm2, mm3, mm0, mm1 */
- MMX_TRANSPOSE ( %%mm2, %%mm4, %%mm1, %%mm3, %%mm0 );
-
- MMX_ZERO( %%mm7 );
- asm volatile( "movq x264_mmx_32, %%mm6\n" :: );
-
- MMX_STORE_DIFF_4P( %%mm2, %%mm4, %%mm6, %%mm7, &p_dst[0*i_dst] );
- MMX_STORE_DIFF_4P( %%mm3, %%mm4, %%mm6, %%mm7, &p_dst[1*i_dst] );
- MMX_STORE_DIFF_4P( %%mm0, %%mm4, %%mm6, %%mm7, &p_dst[2*i_dst] );
- MMX_STORE_DIFF_4P( %%mm1, %%mm4, %%mm6, %%mm7, &p_dst[3*i_dst] );
-}
-#endif
-
-void x264_add8x8_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4][4] )
-{
- x264_add4x4_idct_mmxext( p_dst, i_dst, dct[0] );
- x264_add4x4_idct_mmxext( &p_dst[4], i_dst, dct[1] );
- x264_add4x4_idct_mmxext( &p_dst[4*i_dst+0], i_dst, dct[2] );
- x264_add4x4_idct_mmxext( &p_dst[4*i_dst+4], i_dst, dct[3] );
-}
-
-void x264_add16x16_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[16][4][4] )
-{
- x264_add8x8_idct_mmxext( &p_dst[0], i_dst, &dct[0] );
- x264_add8x8_idct_mmxext( &p_dst[8], i_dst, &dct[4] );
- x264_add8x8_idct_mmxext( &p_dst[8*i_dst], i_dst, &dct[8] );
- x264_add8x8_idct_mmxext( &p_dst[8*i_dst+8], i_dst, &dct[12] );
-}
+++ /dev/null
-;*****************************************************************************
-;* dct.asm: h264 encoder library
-;*****************************************************************************
-;* Copyright (C) 2003 x264 project
-;* $Id: dct.asm,v 1.1 2004/06/03 19:27:07 fenrir Exp $
-;*
-;* Authors: Min Chen <chenm001.163.com> (converted to nasm)
-;* Laurent Aimar <fenrir@via.ecp.fr> (initial version)
-;*
-;* 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.
-;*****************************************************************************
-
-;*****************************************************************************
-;* *
-;* Revision history: *
-;* *
-;* 2004.04.28 portab all 4x4 function to nasm (CM) *
-;* *
-;*****************************************************************************
-
-BITS 32
-
-;=============================================================================
-; Macros and other preprocessor constants
-;=============================================================================
-
-%macro cglobal 1
- %ifdef PREFIX
- global _%1
- %define %1 _%1
- %else
- global %1
- %endif
-%endmacro
-
-%macro MMX_ZERO 1
- pxor %1, %1
-%endmacro
-
-%macro MMX_LOAD_DIFF_4P 5
- movd %1, %4
- punpcklbw %1, %3
- movd %2, %5
- punpcklbw %2, %3
- psubw %1, %2
-%endmacro
-
-%macro MMX_SUMSUB_BA 2
- paddw %1, %2
- paddw %2, %2
- psubw %2, %1
-%endmacro
-
-%macro MMX_SUMSUB_BADC 4
- paddw %1, %2
- paddw %3, %4
- paddw %2, %2
- paddw %4, %4
- psubw %2, %1
- psubw %4, %3
-%endmacro
-
-%macro MMX_SUMSUB2_AB 3
- movq %3, %1
- paddw %1, %1
- paddw %1, %2
- psubw %3, %2
- psubw %3, %2
-%endmacro
-
-%macro MMX_SUMSUBD2_AB 4
- movq %4, %1
- movq %3, %2
- psraw %2, $1
- psraw %4, $1
- paddw %1, %2
- psubw %4, %3
-%endmacro
-
-%macro SBUTTERFLYwd 3
- movq %3, %1
- punpcklwd %1, %2
- punpckhwd %3, %2
-%endmacro
-
-%macro SBUTTERFLYdq 3
- movq %3, %1
- punpckldq %1, %2
- punpckhdq %3, %2
-%endmacro
-
-;-----------------------------------------------------------------------------
-; input ABCD output ADTC
-;-----------------------------------------------------------------------------
-%macro MMX_TRANSPOSE 5
- SBUTTERFLYwd %1, %2, %5
- SBUTTERFLYwd %3, %4, %2
- SBUTTERFLYdq %1, %3, %4
- SBUTTERFLYdq %5, %2, %3
-%endmacro
-
-%macro MMX_STORE_DIFF_4P 5
- paddw %1, %3
- psraw %1, $6
- movd %2, %5
- punpcklbw %2, %4
- paddsw %1, %2
- packuswb %1, %1
- movd %5, %1
-%endmacro
-
-;%macro
-;%endmacro
-
-;=============================================================================
-; Local Data (Read Only)
-;=============================================================================
-
-%ifdef FORMAT_COFF
-SECTION .rodata data
-%else
-SECTION .rodata data align=16
-%endif
-
-;-----------------------------------------------------------------------------
-; Various memory constants (trigonometric values or rounding values)
-;-----------------------------------------------------------------------------
-
-ALIGN 16
-x264_mmx_1:
- dw 1, 1, 1, 1
-
-x264_mmx_32:
- dw 32, 32, 32, 32
-
-;=============================================================================
-; Code
-;=============================================================================
-
-SECTION .text
-
-cglobal x264_dct4x4dc_mmxext
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void __cdecl dct4x4dc( int16_t d[4][4] )
-;-----------------------------------------------------------------------------
-x264_dct4x4dc_mmxext:
- mov eax, [esp+ 4]
- movq mm0, [eax+ 0]
- movq mm1, [eax+ 8]
- movq mm2, [eax+16]
- movq mm3, [eax+24]
-
- MMX_SUMSUB_BADC mm1, mm0, mm3, mm2 ; mm1=s01 mm0=d01 mm3=s23 mm2=d23
- MMX_SUMSUB_BADC mm3, mm1, mm2, mm0 ; mm3=s01+s23 mm1=s01-s23 mm2=d01+d23 mm0=d01-d23
-
- MMX_TRANSPOSE mm3, mm1, mm0, mm2, mm4 ; in: mm3, mm1, mm0, mm2 out: mm3, mm2, mm4, mm0
-
- MMX_SUMSUB_BADC mm2, mm3, mm0, mm4 ; mm2=s01 mm3=d01 mm0=s23 mm4=d23
- MMX_SUMSUB_BADC mm0, mm2, mm4, mm3 ; mm0=s01+s23 mm2=s01-s23 mm4=d01+d23 mm3=d01-d23
-
- MMX_TRANSPOSE mm0, mm2, mm3, mm4, mm1 ; in: mm0, mm2, mm3, mm4 out: mm0, mm4, mm1, mm3
-
- movq mm6, [x264_mmx_1]
- paddw mm0, mm6
- paddw mm4, mm6
- psraw mm0, 1
- movq [eax+ 0], mm0
- psraw mm4, 1
- movq [eax+ 8], mm4
- paddw mm1, mm6
- paddw mm3, mm6
- psraw mm1, 1
- movq [eax+16], mm1
- psraw mm3, 1
- movq [eax+24], mm3
- ret
-
-cglobal x264_idct4x4dc_mmxext
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void __cdecl x264_idct4x4dc_mmxext( int16_t d[4][4] )
-;-----------------------------------------------------------------------------
-x264_idct4x4dc_mmxext:
- mov eax, [esp+ 4]
- movq mm0, [eax+ 0]
- movq mm1, [eax+ 8]
- movq mm2, [eax+16]
- movq mm3, [eax+24]
-
- MMX_SUMSUB_BADC mm1, mm0, mm3, mm2 ; mm1=s01 mm0=d01 mm3=s23 mm2=d23
- MMX_SUMSUB_BADC mm3, mm1, mm2, mm0 ; mm3=s01+s23 mm1=s01-s23 mm2=d01+d23 mm0=d01-d23
-
- MMX_TRANSPOSE mm3, mm1, mm0, mm2, mm4 ; in: mm3, mm1, mm0, mm2 out: mm3, mm2, mm4, mm0
-
- MMX_SUMSUB_BADC mm2, mm3, mm0, mm4 ; mm2=s01 mm3=d01 mm0=s23 mm4=d23
- MMX_SUMSUB_BADC mm0, mm2, mm4, mm3 ; mm0=s01+s23 mm2=s01-s23 mm4=d01+d23 mm3=d01-d23
-
- MMX_TRANSPOSE mm0, mm2, mm3, mm4, mm1 ; in: mm0, mm2, mm3, mm4 out: mm0, mm4, mm1, mm3
-
- movq [eax+ 0], mm0
- movq [eax+ 8], mm4
- movq [eax+16], mm1
- movq [eax+24], mm3
- ret
-
-cglobal x264_sub4x4_dct_mmxext
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void __cdecl x264_sub4x4_dct_mmxext( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
-;-----------------------------------------------------------------------------
-x264_sub4x4_dct_mmxext:
- push ebx
- mov eax, [esp+12] ; pix1
- mov ebx, [esp+16] ; i_pix1
- mov ecx, [esp+20] ; pix2
- mov edx, [esp+24] ; i_pix2
-
- MMX_ZERO mm7
-
- ; Load 4 lines
- MMX_LOAD_DIFF_4P mm0, mm6, mm7, [eax ], [ecx]
- MMX_LOAD_DIFF_4P mm1, mm6, mm7, [eax+ebx ], [ecx+edx]
- MMX_LOAD_DIFF_4P mm2, mm6, mm7, [eax+ebx*2], [ecx+edx*2]
- add eax, ebx
- add ecx, edx
- MMX_LOAD_DIFF_4P mm3, mm6, mm7, [eax+ebx*2], [ecx+edx*2]
-
- MMX_SUMSUB_BADC mm3, mm0, mm2, mm1 ; mm3=s03 mm0=d03 mm2=s12 mm1=d12
-
- MMX_SUMSUB_BA mm2, mm3 ; mm2=s03+s12 mm3=s03-s12
- MMX_SUMSUB2_AB mm0, mm1, mm4 ; mm0=2.d03+d12 mm4=d03-2.d12
-
- ; transpose in: mm2, mm0, mm3, mm4, out: mm2, mm4, mm1, mm3
- MMX_TRANSPOSE mm2, mm0, mm3, mm4, mm1
-
- MMX_SUMSUB_BADC mm3, mm2, mm1, mm4 ; mm3=s03 mm2=d03 mm1=s12 mm4=d12
-
- MMX_SUMSUB_BA mm1, mm3 ; mm1=s03+s12 mm3=s03-s12
- MMX_SUMSUB2_AB mm2, mm4, mm0 ; mm2=2.d03+d12 mm0=d03-2.d12
-
- ; transpose in: mm1, mm2, mm3, mm0, out: mm1, mm0, mm4, mm3
- MMX_TRANSPOSE mm1, mm2, mm3, mm0, mm4
-
- mov eax, [esp+ 8] ; dct
- movq [eax+ 0], mm1
- movq [eax+ 8], mm0
- movq [eax+16], mm4
- movq [eax+24], mm3
-
- pop ebx
- ret
-
-cglobal x264_add4x4_idct_mmxext
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void __cdecl x264_add4x4_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4] )
-;-----------------------------------------------------------------------------
-x264_add4x4_idct_mmxext:
-
- ; Load dct coeffs
- mov eax, [esp+12] ; dct
- movq mm0, [eax+ 0]
- movq mm4, [eax+ 8]
- movq mm3, [eax+16]
- movq mm1, [eax+24]
-
- mov eax, [esp+ 4] ; p_dst
- mov ecx, [esp+ 8] ; i_dst
- lea edx, [ecx+ecx*2]
-
- ; out:mm0, mm1, mm2, mm3
- MMX_TRANSPOSE mm0, mm4, mm3, mm1, mm2
-
- MMX_SUMSUB_BA mm2, mm0 ; mm2=s02 mm0=d02
- MMX_SUMSUBD2_AB mm1, mm3, mm5, mm4 ; mm1=s13 mm4=d13 ( well 1 + 3>>1 and 1>>1 + 3)
-
- MMX_SUMSUB_BADC mm1, mm2, mm4, mm0 ; mm1=s02+s13 mm2=s02-s13 mm4=d02+d13 mm0=d02-d13
-
- ; in: mm1, mm4, mm0, mm2 out: mm1, mm2, mm3, mm0
- MMX_TRANSPOSE mm1, mm4, mm0, mm2, mm3
-
- MMX_SUMSUB_BA mm3, mm1 ; mm3=s02 mm1=d02
- MMX_SUMSUBD2_AB mm2, mm0, mm5, mm4 ; mm2=s13 mm4=d13 ( well 1 + 3>>1 and 1>>1 + 3)
-
- MMX_SUMSUB_BADC mm2, mm3, mm4, mm1 ; mm2=s02+s13 mm3=s02-s13 mm4=d02+d13 mm1=d02-d13
-
- MMX_ZERO mm7
- movq mm6, [x264_mmx_32]
-
- MMX_STORE_DIFF_4P mm2, mm0, mm6, mm7, [eax]
- MMX_STORE_DIFF_4P mm4, mm0, mm6, mm7, [eax+ecx]
- MMX_STORE_DIFF_4P mm1, mm0, mm6, mm7, [eax+ecx*2]
- MMX_STORE_DIFF_4P mm3, mm0, mm6, mm7, [eax+edx]
-
- ret
-
+++ /dev/null
-/*****************************************************************************
- * dct.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: dct.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _I386_DCT_H
-#define _I386_DCT_H 1
-
-void x264_sub4x4_dct_mmxext( int16_t dct[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
-void x264_sub8x8_dct_mmxext( int16_t dct[4][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
-void x264_sub16x16_dct_mmxext( int16_t dct[16][4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 );
-
-void x264_add4x4_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4] );
-void x264_add8x8_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[4][4][4] );
-void x264_add16x16_idct_mmxext( uint8_t *p_dst, int i_dst, int16_t dct[16][4][4] );
-
-void x264_dct4x4dc_mmxext( int16_t d[4][4] );
-void x264_idct4x4dc_mmxext( int16_t d[4][4] );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * mc.c: h264 encoder library (Motion Compensation)
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: mc-c.c,v 1.5 2004/06/18 01:59:58 chenm001 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.
- *****************************************************************************/
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "x264.h" /* DECLARE_ALIGNED */
-#include "../mc.h"
-#include "../clip1.h"
-#include "mc.h"
-
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
-#define USED_UINT64(foo) \
- static const uint64_t foo __asm__ (#foo) __attribute__((used))
-#else
-#define USED_UINT64(foo) \
- static const uint64_t foo __asm__ (#foo) __attribute__((unused))
-#endif
-
-USED_UINT64( x264_w0x10 ) = 0x0010001000100010ULL;
-
-
-#define MMX_ZERO( MMZ ) \
- asm volatile( "pxor " #MMZ ", " #MMZ "\n" :: )
-
-#define MMX_INIT( MMV, NAME ) \
- asm volatile( "movq " #NAME ", " #MMV "\n" :: )
-
-#define MMX_SAVE_4P( MMP, MMZ, dst ) \
- asm volatile( "packuswb " #MMZ "," #MMP "\n" \
- "movd " #MMP ", (%0)" :: "r"(dst) )
-
-#define MMX_LOAD_4P( MMP, MMZ, pix ) \
- asm volatile( "movd (%0), " #MMP "\n" \
- "punpcklbw " #MMZ ", " #MMP "\n" : : "r"(pix) )
-
-#define MMX_LOAD_4x4( MMP1, MMP2, MMP3, MMP4, MMZ, pix, i_pix )\
- MMX_LOAD_4P( MMP1, MMZ, &(pix)[0*(i_pix)] ); \
- MMX_LOAD_4P( MMP2, MMZ, &(pix)[1*(i_pix)] ); \
- MMX_LOAD_4P( MMP3, MMZ, &(pix)[2*(i_pix)] ); \
- MMX_LOAD_4P( MMP4, MMZ, &(pix)[3*(i_pix)] )
-
-#define MMX_LOAD_2x4( MMP1, MMP2, MMZ, pix, i_pix )\
- MMX_LOAD_4P( MMP1, MMZ, &(pix)[0*(i_pix)] ); \
- MMX_LOAD_4P( MMP2, MMZ, &(pix)[1*(i_pix)] )
-
-#define MMX_SAVEPACK_8P( MMP1, MMP2, MMZ, dst ) \
- asm volatile( "packuswb " #MMP2 "," #MMP1 "\n" \
- "movq " #MMP1 ", (%0)\n" :: "r"(dst) )
-
-
-#define MMX_LOAD_8P( MMP1, MMP2, MMZ, pix ) \
- asm volatile( "movq (%0) , " #MMP1 "\n" \
- "movq " #MMP1 ", " #MMP2 "\n" \
- "punpcklbw " #MMZ ", " #MMP1 "\n" \
- "punpckhbw " #MMZ ", " #MMP2 "\n" : : "r"(pix) )
-
-#define MMX_LOAD_2x8( MMP1, MMP2, MMP3, MMP4, MMZ, pix, i_pix )\
- MMX_LOAD_8P( MMP1, MMP2, MMZ, &(pix)[0*(i_pix)] ); \
- MMX_LOAD_8P( MMP3, MMP4, MMZ, &(pix)[1*(i_pix)] )
-
-#define SBUTTERFLYwd(a,b,t )\
- asm volatile( "movq " #a ", " #t " \n\t" \
- "punpcklwd " #b ", " #a " \n\t" \
- "punpckhwd " #b ", " #t " \n\t" :: )
-
-#define SBUTTERFLYdq(a,b,t )\
- asm volatile( "movq " #a ", " #t " \n\t" \
- "punpckldq " #b ", " #a " \n\t" \
- "punpckhdq " #b ", " #t " \n\t" :: )
-
-/* input ABCD output ADTC ( or 0?31-2->0123 ) */
-#define MMX_TRANSPOSE( MMA, MMB, MMC, MMD, MMT ) \
- SBUTTERFLYwd( MMA, MMB, MMT ); \
- SBUTTERFLYwd( MMC, MMD, MMB ); \
- SBUTTERFLYdq( MMA, MMC, MMD ); \
- SBUTTERFLYdq( MMT, MMB, MMC )
-
-/* first pass MM0 = MM0 -5*MM1 */
-#define MMX_FILTERTAP_P1( MMP0, MMP1 ) \
- asm volatile( "psubw " #MMP1 "," #MMP0 "\n" \
- "psllw $2, " #MMP1 "\n" \
- "psubw " #MMP1 "," #MMP0 "\n" :: )
- \
-/* second pass MM0 = MM0 + 20*(MM2+MM3) */
-#define MMX_FILTERTAP_P2( MMP0, MMP2, MMP3 ) \
- asm volatile( "paddw " #MMP3 "," #MMP2 "\n" \
- \
- "psllw $2, " #MMP2 "\n" \
- "paddw " #MMP2 "," #MMP0 "\n" \
- "psllw $2, " #MMP2 "\n" \
- "paddw " #MMP2 "," #MMP0 "\n" :: )
-
-/* last pass: MM0 = ( MM0 -5*MM1 + MM2 + MMV ) >> 5 */
-#define MMX_FILTERTAP_P3( MMP0, MMP1, MMP2, MMV, MMZ ) \
- asm volatile( "psubw " #MMP1 "," #MMP0 "\n" \
- "psllw $2, " #MMP1 "\n" \
- "psubw " #MMP1 "," #MMP0 "\n" \
- \
- "paddw " #MMP2 "," #MMP0 "\n" \
- "paddw " #MMV "," #MMP0 "\n" \
- "psraw $5, " #MMP0 "\n" :: )
-
-#define MMX_FILTERTAP2_P1( MMP0, MMP1, MMP2, MMP3 ) \
- asm volatile( "psubw " #MMP1 "," #MMP0 "\n" \
- "psubw " #MMP3 "," #MMP2 "\n" \
- "psllw $2, " #MMP1 "\n" \
- "psllw $2, " #MMP3 "\n" \
- "psubw " #MMP1 "," #MMP0 "\n" \
- "psubw " #MMP3 "," #MMP2 "\n" :: )
-
-/* second pass MM0 = MM0 + 20*(MM1+MM2) */
-#define MMX_FILTERTAP2_P2( MMP0, MMP1, MMP2, MMP3, MMP4, MMP5 ) \
- asm volatile( "paddw " #MMP2 "," #MMP1 "\n" \
- "paddw " #MMP5 "," #MMP4 "\n" \
- \
- "psllw $2, " #MMP1 "\n" \
- "psllw $2, " #MMP4 "\n" \
- "paddw " #MMP1 "," #MMP0 "\n" \
- "paddw " #MMP4 "," #MMP3 "\n" \
- "psllw $2, " #MMP1 "\n" \
- "psllw $2, " #MMP4 "\n" \
- "paddw " #MMP1 "," #MMP0 "\n" \
- "paddw " #MMP4 "," #MMP3 "\n" :: )
-
-#define MMX_LOAD_1r( m1, dst ) \
- asm volatile( "movq (%0), " #m1 "\n" :: "r"(dst) ); \
-
-#define MMX_SAVE_1r( m1, dst ) \
- asm volatile( "movq " #m1 ", (%0)\n" :: "r"(dst) ); \
-
-#define MMX_LOAD_2r( m1, m2, dst, i_dst ) \
- asm volatile( "movq (%0), " #m1 "\n" :: "r"(&((uint8_t*)dst)[0*(i_dst)]) ); \
- asm volatile( "movq (%0), " #m2 "\n" :: "r"(&((uint8_t*)dst)[1*(i_dst)]) )
-
-#define MMX_SAVE_2r( m1, m2, dst, i_dst ) \
- asm volatile( "movq " #m1 ", (%0)\n" :: "r"(&((uint8_t*)dst)[0*(i_dst)]) ); \
- asm volatile( "movq " #m2 ", (%0)\n" :: "r"(&((uint8_t*)dst)[1*(i_dst)]) )
-
-#define MMX_SAVE_4r( m1, m2, m3, m4, dst, i_dst ) \
- asm volatile( "movq " #m1 ", (%0)\n" :: "r"(&((uint8_t*)dst)[0*(i_dst)]) ); \
- asm volatile( "movq " #m2 ", (%0)\n" :: "r"(&((uint8_t*)dst)[1*(i_dst)]) ); \
- asm volatile( "movq " #m3 ", (%0)\n" :: "r"(&((uint8_t*)dst)[2*(i_dst)]) ); \
- asm volatile( "movq " #m4 ", (%0)\n" :: "r"(&((uint8_t*)dst)[3*(i_dst)]) )
-
-#define MMX_LOAD_4r( m1, m2, m3, m4, dst, i_dst ) \
- asm volatile( "movq (%0), " #m1 "\n" :: "r"(&((uint8_t*)dst)[0*(i_dst)]) ); \
- asm volatile( "movq (%0), " #m2 "\n" :: "r"(&((uint8_t*)dst)[1*(i_dst)]) ); \
- asm volatile( "movq (%0), " #m3 "\n" :: "r"(&((uint8_t*)dst)[2*(i_dst)]) ); \
- asm volatile( "movq (%0), " #m4 "\n" :: "r"(&((uint8_t*)dst)[3*(i_dst)]) )
-
-
-static inline int x264_tapfilter( uint8_t *pix, int i_pix_next )
-{
- return pix[-2*i_pix_next] - 5*pix[-1*i_pix_next] + 20*(pix[0] + pix[1*i_pix_next]) - 5*pix[ 2*i_pix_next] + pix[ 3*i_pix_next];
-}
-static inline int x264_tapfilter1( uint8_t *pix )
-{
- return pix[-2] - 5*pix[-1] + 20*(pix[0] + pix[1]) - 5*pix[ 2] + pix[ 3];
-}
-
-typedef void (*pf_mc_t)(uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height );
-
-/* NASM functions */
-extern void x264_pixel_avg_w4_mmxext( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
-extern void x264_pixel_avg_w8_mmxext( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
-extern void x264_pixel_avg_w16_mmxext( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
-extern void x264_pixel_avg_w16_sse2( uint8_t *, int, uint8_t *, int, uint8_t *, int, int );
-
-/* Macro to define NxM functions */
-/* mc I+H */
-#define MC_IH( name, cpu, width, height, off ) \
-static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
-{ \
- DECLARE_ALIGNED( uint8_t, tmp[width*height], width ); \
- \
- mc_hh_w##width( src, i_src_stride, tmp, width, i_height ); \
- x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
- src+(off), i_src_stride, \
- tmp, width, i_height ); \
-}
-
-/* mc I+V */
-#define MC_IV( name, cpu, width, height, off ) \
-static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
-{ \
- DECLARE_ALIGNED( uint8_t, tmp[width*height], width ); \
- \
- mc_hv_w##width( src, i_src_stride, tmp, width, i_height ); \
- x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
- src+(off), i_src_stride, \
- tmp, width, i_height ); \
-}
-
-/* mc H+V */
-#define MC_HV( name, cpu, width, height, off1, off2 ) \
-static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
-{ \
- DECLARE_ALIGNED( uint8_t, tmp1[width*height], width ); \
- DECLARE_ALIGNED( uint8_t, tmp2[width*height], width ); \
- \
- mc_hv_w##width( src+(off1), i_src_stride, tmp1, width, i_height ); \
- mc_hh_w##width( src+(off2), i_src_stride, tmp2, width, i_height ); \
- x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
- tmp1, width, tmp2, width, \
- i_height ); \
-}
-
-/* mc C+H */
-#define MC_CH( name, cpu, width, height, off ) \
-static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
-{ \
- DECLARE_ALIGNED( uint8_t, tmp1[width*height], width ); \
- DECLARE_ALIGNED( uint8_t, tmp2[width*height], width ); \
- \
- mc_hc_w##width( src, i_src_stride, tmp1, width, i_height ); \
- mc_hh_w##width( src+(off), i_src_stride, tmp2, width, i_height ); \
- x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
- tmp1, width, tmp2, width, \
- i_height ); \
-}
-
-/* mc C+V */
-#define MC_CV( name, cpu, width, height, off ) \
-static void name##_w##width##_##cpu( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height ) \
-{ \
- DECLARE_ALIGNED( uint8_t, tmp1[width*height], width ); \
- DECLARE_ALIGNED( uint8_t, tmp2[width*height], width ); \
- \
- mc_hc_w##width( src, i_src_stride, tmp1, width, i_height ); \
- mc_hv_w##width( src+(off), i_src_stride, tmp2, width, i_height ); \
- x264_pixel_avg_w##width##_##cpu( dst, i_dst_stride, \
- tmp1, width, tmp2, width, \
- i_height ); \
-}
-
-
-/*****************************************************************************
- * MC with width == 4 (height <= 8)
- *****************************************************************************/
-
-extern void x264_mc_copy_w4_mmxext( uint8_t *, int, uint8_t *, int, int );
-
-static inline void mc_hh_w4( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
-{
- const int h4 = i_height / 4;
- uint8_t srct[4*8*3];
- uint64_t tmp[4];
- int y;
-
- src -= 2;
-
- MMX_ZERO( %%mm7 );
- MMX_INIT( %%mm6, x264_w0x10 );
-
- for( y = 0; y < h4; y++ )
- {
- int i;
-
- /* Preload data and transpose them */
- MMX_LOAD_4x4 ( %%mm0, %%mm4, %%mm3, %%mm1, %%mm7, &src[0], i_src );
- MMX_TRANSPOSE( %%mm0, %%mm4, %%mm3, %%mm1, %%mm2 ); /* 0123 */
- MMX_SAVE_4r( %%mm0, %%mm1, %%mm2, %%mm3, &srct[4*8*0], 8 );
-
- MMX_LOAD_4x4 ( %%mm0, %%mm4, %%mm3, %%mm1, %%mm7, &src[4], i_src );
- MMX_TRANSPOSE( %%mm0, %%mm4, %%mm3, %%mm1, %%mm2 ); /* 0123 */
- MMX_SAVE_4r( %%mm0, %%mm1, %%mm2, %%mm3, &srct[4*8*1], 8 );
-
- /* we read 2 more bytes that needed */
- MMX_LOAD_4x4 ( %%mm0, %%mm4, %%mm3, %%mm1, %%mm7, &src[8], i_src );
- MMX_TRANSPOSE( %%mm0, %%mm4, %%mm3, %%mm1, %%mm2 ); /* 0123 */
- MMX_SAVE_2r( %%mm0, %%mm1, &srct[4*8*2], 8 );
-
- /* tap filter */
- for( i = 0; i < 4; i++ )
- {
- MMX_LOAD_4r( %%mm0, %%mm1, %%mm2, %%mm3, &srct[8*(i+0)], 8 );
- MMX_FILTERTAP_P1( %%mm0, %%mm1 );
- MMX_FILTERTAP_P2( %%mm0, %%mm2, %%mm3 );
-
- MMX_LOAD_2r( %%mm1, %%mm2, &srct[8*(i+4)], 8 );
- MMX_FILTERTAP_P3( %%mm0, %%mm1, %%mm2, %%mm6, %%mm7 );
-
- MMX_SAVE_1r( %%mm0, &tmp[i] );
- }
-
- MMX_LOAD_4r( %%mm0, %%mm4, %%mm3, %%mm1, tmp, 8 );
- MMX_TRANSPOSE( %%mm0, %%mm4, %%mm3, %%mm1, %%mm2 ); /* 0123 */
- MMX_SAVE_4P( %%mm0, %%mm7, &dst[0*i_dst] );
- MMX_SAVE_4P( %%mm1, %%mm7, &dst[1*i_dst] );
- MMX_SAVE_4P( %%mm2, %%mm7, &dst[2*i_dst] );
- MMX_SAVE_4P( %%mm3, %%mm7, &dst[3*i_dst] );
-
- src += 4 * i_src;
- dst += 4 * i_dst;
- }
-}
-static inline void mc_hv_w4( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
-{
- int y;
-
- src -= 2 * i_src;
-
- MMX_ZERO( %%mm7 );
- MMX_INIT( %%mm6, x264_w0x10 );
-
- for( y = 0; y < i_height; y++ )
- {
- MMX_LOAD_4x4( %%mm0, %%mm1, %%mm2, %%mm3, %%mm7, src, i_src );
- MMX_FILTERTAP_P1( %%mm0, %%mm1 );
- MMX_FILTERTAP_P2( %%mm0, %%mm2, %%mm3 );
-
- MMX_LOAD_2x4( %%mm4, %%mm5, %%mm7, &src[4*i_src], i_src );
- MMX_FILTERTAP_P3( %%mm0, %%mm4, %%mm5, %%mm6, %%mm7 );
- MMX_SAVE_4P( %%mm0, %%mm7, dst );
-
- src += i_src;
- dst += i_dst;
- }
-}
-
-static inline void mc_hc_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- int i, x, y;
-
- for( y = 0; y < i_height; y++ )
- {
- int16_t tap[5+4];
-
- for( i = 0; i < 5+4; i++ )
- {
- tap[i] = x264_tapfilter( &src[-2+i], i_src_stride );
- }
-
- for( x = 0; x < 4; x++ )
- {
- dst[x] = x264_mc_clip1( ( tap[0+x] - 5*tap[1+x] + 20 * tap[2+x] + 20 * tap[3+x] -5*tap[4+x] + tap[5+x] + 512 ) >> 10 );
- }
-
- src += i_src_stride;
- dst += i_dst_stride;
- }
-}
-
-MC_IH( mc_xy10, mmxext, 4, 8, 0 )
-MC_IH( mc_xy30, mmxext, 4, 8, 1 )
-
-MC_IV( mc_xy01, mmxext, 4, 8, 0 )
-MC_IV( mc_xy03, mmxext, 4, 8, i_src_stride )
-
-MC_HV( mc_xy11, mmxext, 4, 8, 0, 0 )
-MC_HV( mc_xy31, mmxext, 4, 8, 1, 0 )
-MC_HV( mc_xy13, mmxext, 4, 8, 0, i_src_stride )
-MC_HV( mc_xy33, mmxext, 4, 8, 1, i_src_stride )
-
-MC_CH( mc_xy21, mmxext, 4, 8, 0 )
-MC_CH( mc_xy23, mmxext, 4, 8, i_src_stride )
-
-MC_CV( mc_xy12, mmxext, 4, 8, 0 )
-MC_CV( mc_xy32, mmxext, 4, 8, 1 )
-
-#if 0
-static void mc_xy10_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp[4*8];
- mc_hh_w4( src, i_src_stride, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, src, i_src_stride, tmp, 4, i_height );
-}
-static void mc_xy30_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp[4*8];
- mc_hh_w4( src, i_src_stride, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, src+1, i_src_stride, tmp, 4, i_height );
-}
-
-static void mc_xy01_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp[4*8];
- mc_hv_w4( src, i_src_stride, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, src, i_src_stride, tmp, 4, i_height );
-}
-static void mc_xy03_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp[4*8];
- mc_hv_w4( src, i_src_stride, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, src+i_src_stride, i_src_stride, tmp, 4, i_height );
-}
-
-static void mc_xy11_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[4*8];
- uint8_t tmp2[4*8];
-
- mc_hv_w4( src, i_src_stride, tmp1, 4, i_height );
- mc_hh_w4( src, i_src_stride, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy31_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[4*8];
- uint8_t tmp2[4*8];
-
- mc_hv_w4( src+1, i_src_stride, tmp1, 4, i_height );
- mc_hh_w4( src, i_src_stride, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy13_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[4*8];
- uint8_t tmp2[4*8];
-
- mc_hv_w4( src, i_src_stride, tmp1, 4, i_height );
- mc_hh_w4( src+i_src_stride, i_src_stride, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy33_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[4*8];
- uint8_t tmp2[4*8];
-
- mc_hv_w4( src+1, i_src_stride, tmp1, 4, i_height );
- mc_hh_w4( src+i_src_stride, i_src_stride, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
-}
-
-static void mc_xy21_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[4*8];
- uint8_t tmp2[4*8];
-
- mc_hc_w4( src, i_src_stride, tmp1, 4, i_height );
- mc_hh_w4( src, i_src_stride, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy23_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[4*8];
- uint8_t tmp2[4*8];
-
- mc_hc_w4( src, i_src_stride, tmp1, 4, i_height );
- mc_hh_w4( src+i_src_stride, i_src_stride, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
-}
-
-static void mc_xy12_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[4*8];
- uint8_t tmp2[4*8];
-
- mc_hc_w4( src, i_src_stride, tmp1, 4, i_height );
- mc_hv_w4( src, i_src_stride, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy32_w4( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[4*8];
- uint8_t tmp2[4*8];
-
- mc_hc_w4( src, i_src_stride, tmp1, 4, i_height );
- mc_hv_w4( src+1, i_src_stride, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst_stride, tmp1, 4, tmp2, 4, i_height );
-}
-#endif
-
-/*****************************************************************************
- * MC with width == 8 (height <= 16)
- *****************************************************************************/
-extern void x264_mc_copy_w8_mmxext( uint8_t *, int, uint8_t *, int, int );
-
-static inline void mc_hh_w8( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
-{
- mc_hh_w4( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hh_w4( &src[4], i_src, &dst[4], i_dst, i_height );
-}
-static inline void mc_hv_w8( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
-{
- int y;
-
- src -= 2 * i_src;
-
- MMX_ZERO( %%mm7 );
- MMX_INIT( %%mm6, x264_w0x10 );
-
- for( y = 0; y < i_height; y++ )
- {
- MMX_LOAD_2x8( %%mm0, %%mm5, %%mm1, %%mm2, %%mm7, &src[0*i_src], i_src );
- MMX_FILTERTAP2_P1( %%mm0, %%mm1, %%mm5, %%mm2 );
-
-
- MMX_LOAD_2x8( %%mm1, %%mm3, %%mm2, %%mm4, %%mm7, &src[2*i_src], i_src );
- MMX_FILTERTAP2_P2( %%mm0, %%mm1, %%mm2, %%mm5, %%mm3, %%mm4 );
-
- MMX_LOAD_2x8( %%mm1, %%mm3, %%mm2, %%mm4, %%mm7, &src[4*i_src], i_src );
- MMX_FILTERTAP_P3( %%mm0, %%mm1, %%mm2, %%mm6, %%mm7 );
- MMX_FILTERTAP_P3( %%mm5, %%mm3, %%mm4, %%mm6, %%mm7 );
-
- MMX_SAVEPACK_8P( %%mm0, %%mm5, %%mm7, dst );
-
- src += i_src;
- dst += i_dst;
- }
-}
-
-static inline void mc_hc_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- int x, y;
-
- asm volatile( "pxor %%mm7, %%mm7\n" : : );
-
- for( y = 0; y < i_height; y++ )
- {
- int16_t tap[5+8];
-
- /* first 8 */
- asm volatile(
- "leal (%0, %1), %%eax\n"
-
- "movq (%0), %%mm0\n" /* load pix-2 */
- "movq %%mm0, %%mm2\n"
- "punpcklbw %%mm7, %%mm0\n"
- "punpckhbw %%mm7, %%mm2\n"
-
- "movq (%%eax),%%mm1\n" /* load pix-1 */
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7, %%mm1\n"
- "punpckhbw %%mm7, %%mm3\n"
- "psubw %%mm1, %%mm0\n"
- "psllw $2, %%mm1\n"
- "psubw %%mm1, %%mm0\n"
- "psubw %%mm3, %%mm2\n"
- "psllw $2, %%mm3\n"
- "psubw %%mm3, %%mm2\n"
-
- "movq (%%eax,%1),%%mm1\n" /* load pix */
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7, %%mm1\n"
- "punpckhbw %%mm7, %%mm3\n"
- "psllw $2, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
- "psllw $2, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
- "psllw $2, %%mm3\n"
- "paddw %%mm3, %%mm2\n"
- "psllw $2, %%mm3\n"
- "paddw %%mm3, %%mm2\n"
-
- "movq (%%eax,%1,2),%%mm1\n" /* load pix+1 */
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7, %%mm1\n"
- "punpckhbw %%mm7, %%mm3\n"
- "psllw $2, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
- "psllw $2, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
- "psllw $2, %%mm3\n"
- "paddw %%mm3, %%mm2\n"
- "psllw $2, %%mm3\n"
- "paddw %%mm3, %%mm2\n"
-
- "movq (%0,%1,4),%%mm1\n" /* load pix+2 */
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7, %%mm1\n"
- "punpckhbw %%mm7, %%mm3\n"
- "psubw %%mm1, %%mm0\n"
- "psllw $2, %%mm1\n"
- "psubw %%mm1, %%mm0\n"
- "psubw %%mm3, %%mm2\n"
- "psllw $2, %%mm3\n"
- "psubw %%mm3, %%mm2\n"
-
- "movq (%%eax,%1,4),%%mm1\n" /* load pix+3 */
- "movq %%mm1, %%mm3\n"
- "punpcklbw %%mm7, %%mm1\n"
- "punpckhbw %%mm7, %%mm3\n"
- "paddw %%mm1, %%mm0\n"
- "paddw %%mm3, %%mm2\n"
-
- "movq %%mm0, (%2)\n"
- "movq %%mm2, 8(%2)\n"
-
-
- "addl $8, %%eax\n"
- "addl $8, %0\n"
-
-
- "movd (%0), %%mm0\n" /* load pix-2 */
- "punpcklbw %%mm7, %%mm0\n"
-
- "movd (%%eax),%%mm1\n" /* load pix-1 */
- "punpcklbw %%mm7, %%mm1\n"
- "psubw %%mm1, %%mm0\n"
- "psllw $2, %%mm1\n"
- "psubw %%mm1, %%mm0\n"
-
- "movd (%%eax,%1),%%mm1\n" /* load pix */
- "punpcklbw %%mm7, %%mm1\n"
- "psllw $2, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
- "psllw $2, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
-
- "movd (%%eax,%1,2),%%mm1\n" /* load pix+1 */
- "punpcklbw %%mm7, %%mm1\n"
- "psllw $2, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
- "psllw $2, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
-
- "movd (%0,%1,4),%%mm1\n" /* load pix+2 */
- "punpcklbw %%mm7, %%mm1\n"
- "psubw %%mm1, %%mm0\n"
- "psllw $2, %%mm1\n"
- "psubw %%mm1, %%mm0\n"
-
- "movd (%%eax,%1,4),%%mm1\n" /* load pix+3 */
- "punpcklbw %%mm7, %%mm1\n"
- "paddw %%mm1, %%mm0\n"
-
- "movq %%mm0, 16(%2)\n"
- : : "r"(src-2*i_src_stride-2), "r"(i_src_stride), "r"(&tap[0]) : "%eax" );
-
- /* last one */
- tap[8+4] = x264_tapfilter( &src[-2+8+4], i_src_stride );
-
- for( x = 0; x < 8; x++ )
- {
- dst[x] = x264_mc_clip1( ( tap[0+x] - 5*tap[1+x] + 20 * tap[2+x] + 20 * tap[3+x] -5*tap[4+x] + tap[5+x] + 512 ) >> 10 );
- }
-
- src += i_src_stride;
- dst += i_dst_stride;
- }
-}
-
-MC_IH( mc_xy10, mmxext, 8, 16, 0 )
-MC_IH( mc_xy30, mmxext, 8, 16, 1 )
-
-MC_IV( mc_xy01, mmxext, 8, 16, 0 )
-MC_IV( mc_xy03, mmxext, 8, 16, i_src_stride )
-
-MC_HV( mc_xy11, mmxext, 8, 16, 0, 0 )
-MC_HV( mc_xy31, mmxext, 8, 16, 1, 0 )
-MC_HV( mc_xy13, mmxext, 8, 16, 0, i_src_stride )
-MC_HV( mc_xy33, mmxext, 8, 16, 1, i_src_stride )
-
-MC_CH( mc_xy21, mmxext, 8, 16, 0 )
-MC_CH( mc_xy23, mmxext, 8, 16, i_src_stride )
-
-MC_CV( mc_xy12, mmxext, 8, 16, 0 )
-MC_CV( mc_xy32, mmxext, 8, 16, 1 )
-
-#if 0
-/* mc I+H */
-static void mc_xy10_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp[8*16];
- mc_hh_w8( src, i_src_stride, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, src, i_src_stride, tmp, 8, i_height );
-}
-static void mc_xy30_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp[8*16];
- mc_hh_w8( src, i_src_stride, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, src+1, i_src_stride, tmp, 8, i_height );
-}
-/* mc I+V */
-static void mc_xy01_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp[8*16];
- mc_hv_w8( src, i_src_stride, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, src, i_src_stride, tmp, 8, i_height );
-}
-static void mc_xy03_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp[8*16];
- mc_hv_w8( src, i_src_stride, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, src+i_src_stride, i_src_stride, tmp, 8, i_height );
-}
-/* H+V */
-static void mc_xy11_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[8*16];
- uint8_t tmp2[8*16];
-
- mc_hv_w8( src, i_src_stride, tmp1, 8, i_height );
- mc_hh_w8( src, i_src_stride, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy31_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[8*16];
- uint8_t tmp2[8*16];
-
- mc_hv_w8( src+1, i_src_stride, tmp1, 8, i_height );
- mc_hh_w8( src, i_src_stride, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy13_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[8*16];
- uint8_t tmp2[8*16];
-
- mc_hv_w8( src, i_src_stride, tmp1, 8, i_height );
- mc_hh_w8( src+i_src_stride, i_src_stride, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy33_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[8*16];
- uint8_t tmp2[8*16];
-
- mc_hv_w8( src+1, i_src_stride, tmp1, 8, i_height );
- mc_hh_w8( src+i_src_stride, i_src_stride, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy21_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[8*16];
- uint8_t tmp2[8*16];
-
- mc_hc_w8( src, i_src_stride, tmp1, 8, i_height );
- mc_hh_w8( src, i_src_stride, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy12_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[8*16];
- uint8_t tmp2[8*16];
-
- mc_hc_w8( src, i_src_stride, tmp1, 8, i_height );
- mc_hv_w8( src, i_src_stride, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy32_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[8*16];
- uint8_t tmp2[8*16];
-
- mc_hc_w8( src, i_src_stride, tmp1, 8, i_height );
- mc_hv_w8( src+1, i_src_stride, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy23_w8( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- uint8_t tmp1[8*16];
- uint8_t tmp2[8*16];
-
- mc_hc_w8( src, i_src_stride, tmp1, 8, i_height );
- mc_hh_w8( src+i_src_stride, i_src_stride, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst_stride, tmp1, 8, tmp2, 8, i_height );
-}
-#endif
-
-/*****************************************************************************
- * MC with width == 16 (height <= 16)
- *****************************************************************************/
-
-extern void x264_mc_copy_w16_mmxext( uint8_t *, int, uint8_t *, int, int );
-extern void x264_mc_copy_w16_sse2( uint8_t *, int, uint8_t *, int, int );
-
-static inline void mc_hh_w16( uint8_t *src, int i_src, uint8_t *dst, int i_dst, int i_height )
-{
- mc_hh_w4( &src[ 0], i_src, &dst[ 0], i_dst, i_height );
- mc_hh_w4( &src[ 4], i_src, &dst[ 4], i_dst, i_height );
- mc_hh_w4( &src[ 8], i_src, &dst[ 8], i_dst, i_height );
- mc_hh_w4( &src[12], i_src, &dst[12], i_dst, i_height );
-}
-static inline void mc_hv_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- mc_hv_w8( src, i_src_stride, dst, i_dst_stride, i_height );
- mc_hv_w8( &src[8], i_src_stride, &dst[8], i_dst_stride, i_height );
-}
-
-static inline void mc_hc_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- mc_hc_w8( src, i_src_stride, dst, i_dst_stride, i_height );
- mc_hc_w8( &src[8], i_src_stride, &dst[8], i_dst_stride, i_height );
-}
-
-/* MMX avg/copy */
-MC_IH( mc_xy10, mmxext, 16, 16, 0 )
-MC_IH( mc_xy30, mmxext, 16, 16, 1 )
-
-MC_IV( mc_xy01, mmxext, 16, 16, 0 )
-MC_IV( mc_xy03, mmxext, 16, 16, i_src_stride )
-
-MC_HV( mc_xy11, mmxext, 16, 16, 0, 0 )
-MC_HV( mc_xy31, mmxext, 16, 16, 1, 0 )
-MC_HV( mc_xy13, mmxext, 16, 16, 0, i_src_stride )
-MC_HV( mc_xy33, mmxext, 16, 16, 1, i_src_stride )
-
-MC_CH( mc_xy21, mmxext, 16, 16, 0 )
-MC_CH( mc_xy23, mmxext, 16, 16, i_src_stride )
-
-MC_CV( mc_xy12, mmxext, 16, 16, 0 )
-MC_CV( mc_xy32, mmxext, 16, 16, 1 )
-
-/* SSE2 avg/copy */
-MC_IH( mc_xy10, sse2, 16, 16, 0 )
-MC_IH( mc_xy30, sse2, 16, 16, 1 )
-
-MC_IV( mc_xy01, sse2, 16, 16, 0 )
-MC_IV( mc_xy03, sse2, 16, 16, i_src_stride )
-
-MC_HV( mc_xy11, sse2, 16, 16, 0, 0 )
-MC_HV( mc_xy31, sse2, 16, 16, 1, 0 )
-MC_HV( mc_xy13, sse2, 16, 16, 0, i_src_stride )
-MC_HV( mc_xy33, sse2, 16, 16, 1, i_src_stride )
-
-MC_CH( mc_xy21, sse2, 16, 16, 0 )
-MC_CH( mc_xy23, sse2, 16, 16, i_src_stride )
-
-MC_CV( mc_xy12, sse2, 16, 16, 0 )
-MC_CV( mc_xy32, sse2, 16, 16, 1 )
-
-
-#if 0
-/* mc I+H */
-static void mc_xy10_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp[16*16], 16);
- mc_hh_w16( src, i_src_stride, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, src, i_src_stride, tmp, 16, i_height );
-}
-static void mc_xy30_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp[16*16], 16);
- mc_hh_w16( src, i_src_stride, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, src+1, i_src_stride, tmp, 16, i_height );
-}
-/* mc I+V */
-static void mc_xy01_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp[16*16], 16);
- mc_hv_w16( src, i_src_stride, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, src, i_src_stride, tmp, 16, i_height );
-}
-static void mc_xy03_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp[16*16], 16);
- mc_hv_w16( src, i_src_stride, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, src+i_src_stride, i_src_stride, tmp, 16, i_height );
-}
-/* H+V */
-static void mc_xy11_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
- DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
-
- mc_hv_w16( src, i_src_stride, tmp1, 16, i_height );
- mc_hh_w16( src, i_src_stride, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
-}
-static void mc_xy31_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
- DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
-
- mc_hv_w16( src+1, i_src_stride, tmp1, 16, i_height );
- mc_hh_w16( src, i_src_stride, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
-}
-static void mc_xy13_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
- DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
-
- mc_hv_w16( src, i_src_stride, tmp1, 16, i_height );
- mc_hh_w16( src+i_src_stride, i_src_stride, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
-}
-static void mc_xy33_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
- DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
-
- mc_hv_w16( src+1, i_src_stride, tmp1, 16, i_height );
- mc_hh_w16( src+i_src_stride, i_src_stride, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
-}
-static void mc_xy21_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
- DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
-
- mc_hc_w16( src, i_src_stride, tmp1, 16, i_height );
- mc_hh_w16( src, i_src_stride, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
-}
-static void mc_xy12_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
- DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
-
- mc_hc_w16( src, i_src_stride, tmp1, 16, i_height );
- mc_hv_w16( src, i_src_stride, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
-}
-static void mc_xy32_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
- DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
-
- mc_hc_w16( src, i_src_stride, tmp1, 16, i_height );
- mc_hv_w16( src+1, i_src_stride, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
-}
-static void mc_xy23_w16( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-{
- DECLARE_ALIGNED(uint8_t, tmp1[16*16], 16);
- DECLARE_ALIGNED(uint8_t, tmp2[16*16], 16);
-
- mc_hc_w16( src, i_src_stride, tmp1, 16, i_height );
- mc_hh_w16( src+i_src_stride, i_src_stride, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst_stride, tmp1, 16, tmp2, 16, i_height );
-}
-#endif
-
-#define MOTION_COMPENSATION_LUMA \
- src += (mvy >> 2) * i_src_stride + (mvx >> 2); \
- if( i_width == 4 ) \
- { \
- pf_mc[0][mvy&0x03][mvx&0x03]( src, i_src_stride, dst, i_dst_stride, i_height ); \
- } \
- else if( i_width == 8 ) \
- { \
- pf_mc[1][mvy&0x03][mvx&0x03]( src, i_src_stride, dst, i_dst_stride, i_height ); \
- } \
- else if( i_width == 16 ) \
- { \
- pf_mc[2][mvy&0x03][mvx&0x03]( src, i_src_stride, dst, i_dst_stride, i_height ); \
- } \
- else \
- { \
- fprintf( stderr, "Error: motion_compensation_luma called with invalid width" ); \
- }
-
-static void motion_compensation_luma_mmxext( uint8_t *src, int i_src_stride,
- uint8_t *dst, int i_dst_stride,
- int mvx,int mvy,
- int i_width, int i_height )
-{
- static const pf_mc_t pf_mc[3][4][4] = /*XXX [dqy][dqx] */
- {
- {
- { x264_mc_copy_w4_mmxext, mc_xy10_w4_mmxext, mc_hh_w4, mc_xy30_w4_mmxext },
- { mc_xy01_w4_mmxext, mc_xy11_w4_mmxext, mc_xy21_w4_mmxext, mc_xy31_w4_mmxext },
- { mc_hv_w4, mc_xy12_w4_mmxext, mc_hc_w4, mc_xy32_w4_mmxext },
- { mc_xy03_w4_mmxext, mc_xy13_w4_mmxext, mc_xy23_w4_mmxext, mc_xy33_w4_mmxext },
- },
- {
- { x264_mc_copy_w8_mmxext, mc_xy10_w8_mmxext, mc_hh_w8, mc_xy30_w8_mmxext },
- { mc_xy01_w8_mmxext, mc_xy11_w8_mmxext, mc_xy21_w8_mmxext, mc_xy31_w8_mmxext },
- { mc_hv_w8, mc_xy12_w8_mmxext, mc_hc_w8, mc_xy32_w8_mmxext },
- { mc_xy03_w8_mmxext, mc_xy13_w8_mmxext, mc_xy23_w8_mmxext, mc_xy33_w8_mmxext },
- },
- {
- { x264_mc_copy_w16_mmxext, mc_xy10_w16_mmxext, mc_hh_w16, mc_xy30_w16_mmxext },
- { mc_xy01_w16_mmxext, mc_xy11_w16_mmxext, mc_xy21_w16_mmxext, mc_xy31_w16_mmxext },
- { mc_hv_w16, mc_xy12_w16_mmxext, mc_hc_w16, mc_xy32_w16_mmxext },
- { mc_xy03_w16_mmxext, mc_xy13_w16_mmxext, mc_xy23_w16_mmxext, mc_xy33_w16_mmxext },
- }
- };
-
- MOTION_COMPENSATION_LUMA
-}
-
-static void motion_compensation_luma_sse2( uint8_t *src, int i_src_stride,
- uint8_t *dst, int i_dst_stride,
- int mvx,int mvy,
- int i_width, int i_height )
-{
- static const pf_mc_t pf_mc[3][4][4] = /*XXX [dqy][dqx] */
- {
- {
- { x264_mc_copy_w4_mmxext, mc_xy10_w4_mmxext, mc_hh_w4, mc_xy30_w4_mmxext },
- { mc_xy01_w4_mmxext, mc_xy11_w4_mmxext, mc_xy21_w4_mmxext, mc_xy31_w4_mmxext },
- { mc_hv_w4, mc_xy12_w4_mmxext, mc_hc_w4, mc_xy32_w4_mmxext },
- { mc_xy03_w4_mmxext, mc_xy13_w4_mmxext, mc_xy23_w4_mmxext, mc_xy33_w4_mmxext },
- },
- {
- { x264_mc_copy_w8_mmxext, mc_xy10_w8_mmxext, mc_hh_w8, mc_xy30_w8_mmxext },
- { mc_xy01_w8_mmxext, mc_xy11_w8_mmxext, mc_xy21_w8_mmxext, mc_xy31_w8_mmxext },
- { mc_hv_w8, mc_xy12_w8_mmxext, mc_hc_w8, mc_xy32_w8_mmxext },
- { mc_xy03_w8_mmxext, mc_xy13_w8_mmxext, mc_xy23_w8_mmxext, mc_xy33_w8_mmxext },
- },
- {
- { x264_mc_copy_w16_sse2, mc_xy10_w16_sse2, mc_hh_w16, mc_xy30_w16_sse2 },
- { mc_xy01_w16_sse2, mc_xy11_w16_sse2, mc_xy21_w16_sse2, mc_xy31_w16_sse2 },
- { mc_hv_w16, mc_xy12_w16_sse2, mc_hc_w16, mc_xy32_w16_sse2 },
- { mc_xy03_w16_sse2, mc_xy13_w16_sse2, mc_xy23_w16_sse2, mc_xy33_w16_sse2 },
- }
- };
- MOTION_COMPENSATION_LUMA
-}
-
-void x264_mc_mmxext_init( x264_mc_function_t pf[2] )
-{
- pf[MC_LUMA] = motion_compensation_luma_mmxext;
-}
-void x264_mc_sse2_init( x264_mc_function_t pf[2] )
-{
- pf[MC_LUMA] = motion_compensation_luma_sse2;
-}
-
+++ /dev/null
-;*****************************************************************************
-;* mc.asm: h264 encoder library
-;*****************************************************************************
-;* Copyright (C) 2003 x264 project
-;* $Id: mc.asm,v 1.3 2004/06/18 01:59:58 chenm001 Exp $
-;*
-;* Authors: Min Chen <chenm001.163.com> (converted to nasm)
-;* Laurent Aimar <fenrir@via.ecp.fr> (init algorithm)
-;*
-;* 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.
-;*****************************************************************************
-
-;*****************************************************************************
-;* *
-;* Revision history: *
-;* *
-;* 2004.05.17 portab mc_copy_w4/8/16 (CM) *
-;* *
-;*****************************************************************************
-
-BITS 32
-
-;=============================================================================
-; Macros and other preprocessor constants
-;=============================================================================
-
-%macro cglobal 1
- %ifdef PREFIX
- global _%1
- %define %1 _%1
- %else
- global %1
- %endif
-%endmacro
-
-;=============================================================================
-; Local Data (Read Only)
-;=============================================================================
-
-%ifdef FORMAT_COFF
-SECTION .rodata data
-%else
-SECTION .rodata data align=16
-%endif
-
-;-----------------------------------------------------------------------------
-; Various memory constants (trigonometric values or rounding values)
-;-----------------------------------------------------------------------------
-
-ALIGN 16
-
-;=============================================================================
-; Code
-;=============================================================================
-
-SECTION .text
-
-cglobal x264_pixel_avg_w4_mmxext
-cglobal x264_pixel_avg_w8_mmxext
-cglobal x264_pixel_avg_w16_mmxext
-cglobal x264_pixel_avg_w16_sse2
-
-cglobal x264_mc_copy_w4_mmxext
-cglobal x264_mc_copy_w8_mmxext
-cglobal x264_mc_copy_w16_mmxext
-cglobal x264_mc_copy_w16_sse2
-
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void x264_pixel_avg_w4_mmxext( uint8_t *dst, int i_dst_stride,
-; uint8_t *src1, int i_src1_stride,
-; uint8_t *src2, int i_src2_stride,
-; int i_height );
-;-----------------------------------------------------------------------------
-x264_pixel_avg_w4_mmxext:
- push ebp
- push ebx
- push esi
- push edi
-
- mov edi, [esp+20] ; dst
- mov ebx, [esp+28] ; src1
- mov ecx, [esp+36] ; src2
- mov esi, [esp+24] ; i_dst_stride
- mov eax, [esp+32] ; i_src1_stride
- mov edx, [esp+40] ; i_src2_stride
- mov ebp, [esp+44] ; i_height
-ALIGN 4
-.height_loop
- movd mm0, [ebx]
- pavgb mm0, [ecx]
- movd mm1, [ebx+eax]
- pavgb mm1, [ecx+edx]
- movd [edi], mm0
- movd [edi+esi], mm1
- dec ebp
- dec ebp
- lea ebx, [ebx+eax*2]
- lea ecx, [ecx+edx*2]
- lea edi, [edi+esi*2]
- jne .height_loop
-
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
-
-
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void x264_pixel_avg_w8_mmxext( uint8_t *dst, int i_dst_stride,
-; uint8_t *src1, int i_src1_stride,
-; uint8_t *src2, int i_src2_stride,
-; int i_height );
-;-----------------------------------------------------------------------------
-x264_pixel_avg_w8_mmxext:
- push ebp
- push ebx
- push esi
- push edi
-
- mov edi, [esp+20] ; dst
- mov ebx, [esp+28] ; src1
- mov ecx, [esp+36] ; src2
- mov esi, [esp+24] ; i_dst_stride
- mov eax, [esp+32] ; i_src1_stride
- mov edx, [esp+40] ; i_src2_stride
- mov ebp, [esp+44] ; i_height
-ALIGN 4
-.height_loop
- movq mm0, [ebx]
- pavgb mm0, [ecx]
- movq [edi], mm0
- dec ebp
- lea ebx, [ebx+eax]
- lea ecx, [ecx+edx]
- lea edi, [edi+esi]
- jne .height_loop
-
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
-
-
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void x264_pixel_avg_w16_mmxext( uint8_t *dst, int i_dst_stride,
-; uint8_t *src1, int i_src1_stride,
-; uint8_t *src2, int i_src2_stride,
-; int i_height );
-;-----------------------------------------------------------------------------
-x264_pixel_avg_w16_mmxext:
- push ebp
- push ebx
- push esi
- push edi
-
- mov edi, [esp+20] ; dst
- mov ebx, [esp+28] ; src1
- mov ecx, [esp+36] ; src2
- mov esi, [esp+24] ; i_dst_stride
- mov eax, [esp+32] ; i_src1_stride
- mov edx, [esp+40] ; i_src2_stride
- mov ebp, [esp+44] ; i_height
-ALIGN 4
-.height_loop
- movq mm0, [ebx ]
- movq mm1, [ebx+8]
- pavgb mm0, [ecx ]
- pavgb mm1, [ecx+8]
- movq [edi ], mm0
- movq [edi+8], mm1
- dec ebp
- lea ebx, [ebx+eax]
- lea ecx, [ecx+edx]
- lea edi, [edi+esi]
- jne .height_loop
-
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void x264_pixel_avg_w16_sse2( uint8_t *dst, int i_dst_stride,
-; uint8_t *src1, int i_src1_stride,
-; uint8_t *src2, int i_src2_stride,
-; int i_height );
-;-----------------------------------------------------------------------------
-x264_pixel_avg_w16_sse2:
- push ebp
- push ebx
- push esi
- push edi
-
- mov edi, [esp+20] ; dst
- mov ebx, [esp+28] ; src1
- mov ecx, [esp+36] ; src2
- mov esi, [esp+24] ; i_dst_stride
- mov eax, [esp+32] ; i_src1_stride
- mov edx, [esp+40] ; i_src2_stride
- mov ebp, [esp+44] ; i_height
-ALIGN 4
-.height_loop
- movdqu xmm0, [ebx]
- pavgb xmm0, [ecx]
- movdqu [edi], xmm0
-
- dec ebp
- lea ebx, [ebx+eax]
- lea ecx, [ecx+edx]
- lea edi, [edi+esi]
- jne .height_loop
-
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
-
-
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void x264_mc_copy_w4_mmxext( uint8_t *src, int i_src_stride,
-; uint8_t *dst, int i_dst_stride, int i_height )
-;-----------------------------------------------------------------------------
-x264_mc_copy_w4_mmxext:
- push ebx
- push esi
- push edi
-
- mov esi, [esp+16] ; src
- mov edi, [esp+24] ; dst
- mov ebx, [esp+20] ; i_src_stride
- mov edx, [esp+28] ; i_dst_stride
- mov ecx, [esp+32] ; i_height
-ALIGN 4
-.height_loop
- mov eax, [esi]
- mov [edi], eax
- mov eax, [esi+ebx]
- mov [edi+edx], eax
- lea esi, [esi+ebx*2]
- lea edi, [edi+edx*2]
- dec ecx
- dec ecx
- jne .height_loop
-
- pop edi
- pop esi
- pop ebx
- ret
-
-cglobal mc_copy_w8
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void x264_mc_copy_w8_mmxext( uint8_t *src, int i_src_stride,
-; uint8_t *dst, int i_dst_stride, int i_height )
-;-----------------------------------------------------------------------------
-x264_mc_copy_w8_mmxext:
- push ebx
- push esi
- push edi
-
- mov esi, [esp+16] ; src
- mov edi, [esp+24] ; dst
- mov ebx, [esp+20] ; i_src_stride
- mov edx, [esp+28] ; i_dst_stride
- mov ecx, [esp+32] ; i_height
-ALIGN 4
-.height_loop
- movq mm0, [esi]
- movq [edi], mm0
- movq mm1, [esi+ebx]
- movq [edi+edx], mm1
- movq mm2, [esi+ebx*2]
- movq [edi+edx*2], mm2
- lea esi, [esi+ebx*2]
- lea edi, [edi+edx*2]
- movq mm3, [esi+ebx]
- movq [edi+edx], mm3
- lea esi, [esi+ebx*2]
- lea edi, [edi+edx*2]
-
- sub ecx, byte 4
- jnz .height_loop
-
- pop edi
- pop esi
- pop ebx
- ret
-
-cglobal mc_copy_w16
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void x264_mc_copy_w16_mmxext( uint8_t *src, int i_src_stride,
-; uint8_t *dst, int i_dst_stride, int i_height )
-;-----------------------------------------------------------------------------
-x264_mc_copy_w16_mmxext:
- push ebx
- push esi
- push edi
-
- mov esi, [esp+16] ; src
- mov edi, [esp+24] ; dst
- mov ebx, [esp+20] ; i_src_stride
- mov edx, [esp+28] ; i_dst_stride
- mov ecx, [esp+32] ; i_height
-
-ALIGN 4
-.height_loop
- movq mm0, [esi]
- movq mm1, [esi+8]
- movq [edi], mm0
- movq [edi+8], mm1
- movq mm2, [esi+ebx]
- movq mm3, [esi+ebx+8]
- movq [edi+edx], mm2
- movq [edi+edx+8], mm3
- movq mm4, [esi+ebx*2]
- movq mm5, [esi+ebx*2+8]
- movq [edi+edx*2], mm4
- movq [edi+edx*2+8], mm5
- lea esi, [esi+ebx*2]
- lea edi, [edi+edx*2]
- movq mm6, [esi+ebx]
- movq mm7, [esi+ebx+8]
- movq [edi+edx], mm6
- movq [edi+edx+8], mm7
- lea esi, [esi+ebx*2]
- lea edi, [edi+edx*2]
- sub ecx, byte 4
- jnz .height_loop
-
- pop edi
- pop esi
- pop ebx
- ret
-
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; void x264_mc_copy_w16_sse2( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_height )
-;-----------------------------------------------------------------------------
-x264_mc_copy_w16_sse2:
- push ebx
- push esi
- push edi
-
- mov esi, [esp+16] ; src
- mov edi, [esp+24] ; dst
- mov ebx, [esp+20] ; i_src_stride
- mov edx, [esp+28] ; i_dst_stride
- mov ecx, [esp+32] ; i_height
-
-ALIGN 4
-.height_loop
- movdqu xmm0, [esi]
- movdqu xmm1, [esi+ebx]
- movdqu [edi], xmm0
- movdqu [edi+edx], xmm1
- dec ecx
- dec ecx
- lea esi, [esi+ebx*2]
- lea edi, [edi+edx*2]
- jnz .height_loop
-
- pop edi
- pop esi
- pop ebx
- ret
+++ /dev/null
-/*****************************************************************************
- * mc.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: mc.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _I386_MC_H
-#define _I386_MC_H 1
-
-void x264_mc_mmxext_init( x264_mc_function_t pf[2] );
-void x264_mc_sse2_init( x264_mc_function_t pf[2] );
-
-#endif
+++ /dev/null
-;*****************************************************************************
-;* pixel.asm: h264 encoder library
-;*****************************************************************************
-;* Copyright (C) 2003 x264 project
-;* $Id: pixel.asm,v 1.1 2004/06/03 19:27:07 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.
-;*****************************************************************************
-
-BITS 32
-
-;=============================================================================
-; Macros and other preprocessor constants
-;=============================================================================
-
-%macro cglobal 1
- %ifdef PREFIX
- global _%1
- %define %1 _%1
- %else
- global %1
- %endif
-%endmacro
-
-%macro SAD_INC_2x16P 0
- movq mm1, [eax]
- movq mm2, [ecx]
- movq mm3, [eax+8]
- movq mm4, [ecx+8]
-
- psadbw mm1, mm2
- psadbw mm3, mm4
- paddw mm0, mm1
- paddw mm0, mm3
-
- movq mm1, [eax+ebx]
- movq mm2, [ecx+edx]
- movq mm3, [eax+ebx+8]
- movq mm4, [ecx+edx+8]
-
- psadbw mm1, mm2
- psadbw mm3, mm4
- paddw mm0, mm1
- paddw mm0, mm3
-
- lea eax, [eax+2*ebx]
- lea ecx, [ecx+2*edx]
-%endmacro
-
-%macro SAD_INC_2x8P 0
- movq mm1, [eax]
- movq mm2, [ecx]
- movq mm3, [eax+ebx]
- movq mm4, [ecx+edx]
-
- psadbw mm1, mm2
- psadbw mm3, mm4
- paddw mm0, mm1
- paddw mm0, mm3
-
- lea eax, [eax+2*ebx]
- lea ecx, [ecx+2*edx]
-%endmacro
-
-%macro SAD_INC_2x4P 0
- movd mm1, [eax]
- movd mm2, [ecx]
- movd mm3, [eax+ebx]
- movd mm4, [ecx+edx]
-
- psadbw mm1, mm2
- psadbw mm3, mm4
- paddw mm0, mm1
- paddw mm0, mm3
-
- lea eax, [eax+2*ebx]
- lea ecx, [ecx+2*edx]
-%endmacro
-
-%macro LOAD_DIFF_4P 5 ; MMP, MMT, MMZ, [pix1], [pix2]
- movd %1, %4
- punpcklbw %1, %3
- movd %2, %5
- punpcklbw %2, %3
- psubw %1, %2
-%endmacro
-
-%macro LOAD_DIFF_INC_4x4 11 ; p1,p2,p3,p4, t, z, pix1, i_pix1, pix2, i_pix2, offset
- LOAD_DIFF_4P %1, %5, %6, [%7+%11], [%9+%11]
- LOAD_DIFF_4P %2, %5, %6, [%7+%8+%11], [%9+%10+%11]
- lea %7, [%7+2*%8]
- lea %9, [%9+2*%10]
- LOAD_DIFF_4P %3, %5, %6, [%7+%11], [%9+%11]
- LOAD_DIFF_4P %4, %5, %6, [%7+%8+%11], [%9+%10+%11]
- lea %7, [%7+2*%8]
- lea %9, [%9+2*%10]
-%endmacro
-
-%macro HADAMARD4_SUB_BADC 4
- paddw %1, %2
- paddw %3, %4
- paddw %2, %2
- paddw %4, %4
- psubw %2, %1
- psubw %4, %3
-%endmacro
-
-%macro HADAMARD4x4 4
- HADAMARD4_SUB_BADC %1, %2, %3, %4
- HADAMARD4_SUB_BADC %1, %3, %2, %4
-%endmacro
-
-%macro SBUTTERFLYwd 3
- movq %3, %1
- punpcklwd %1, %2
- punpckhwd %3, %2
-%endmacro
-
-%macro SBUTTERFLYdq 3
- movq %3, %1
- punpckldq %1, %2
- punpckhdq %3, %2
-%endmacro
-
-%macro TRANSPOSE4x4 5 ; abcd-t -> adtc
- SBUTTERFLYwd %1, %2, %5
- SBUTTERFLYwd %3, %4, %2
- SBUTTERFLYdq %1, %3, %4
- SBUTTERFLYdq %5, %2, %3
-%endmacro
-
-%macro MMX_ABS 2 ; mma, mmt
- pxor %2, %2
- psubw %2, %1
- pmaxsw %1, %2
-%endmacro
-
-%macro MMX_ABS_SUM 3 ; mma, mmt, mms
- pxor %2, %2
- psubw %2, %1
- pmaxsw %1, %2
- paddusw %3, %1
-%endmacro
-
-
-%macro MMX_SUM_MM 2 ; mmv, mmt
- movq %2, %1
- psrlq %1, 32
- paddusw %1, %2
- movq %2, %1
- psrlq %1, 16
- paddusw %1, %2
- movd eax,%1
- and eax,0xffff
- shr eax,1
-%endmacro
-
-%macro HADAMARD4x4_FIRST 0
- HADAMARD4x4 mm0, mm1, mm2, mm3
- TRANSPOSE4x4 mm0, mm1, mm2, mm3, mm4
- HADAMARD4x4 mm0, mm3, mm4, mm2
- MMX_ABS mm0, mm7
- MMX_ABS_SUM mm3, mm7, mm0
- MMX_ABS_SUM mm4, mm7, mm0
- MMX_ABS_SUM mm2, mm7, mm0
-%endmacro
-
-%macro HADAMARD4x4_NEXT 0
- HADAMARD4x4 mm1, mm2, mm3, mm4
- TRANSPOSE4x4 mm1, mm2, mm3, mm4, mm5
- HADAMARD4x4 mm1, mm4, mm5, mm3
- MMX_ABS_SUM mm1, mm7, mm0
- MMX_ABS_SUM mm4, mm7, mm0
- MMX_ABS_SUM mm5, mm7, mm0
- MMX_ABS_SUM mm3, mm7, mm0
-%endmacro
-
-;=============================================================================
-; Code
-;=============================================================================
-
-SECTION .text
-
-cglobal x264_pixel_sad_16x16_mmxext
-cglobal x264_pixel_sad_16x8_mmxext
-cglobal x264_pixel_sad_8x16_mmxext
-cglobal x264_pixel_sad_8x8_mmxext
-cglobal x264_pixel_sad_8x4_mmxext
-cglobal x264_pixel_sad_4x8_mmxext
-cglobal x264_pixel_sad_4x4_mmxext
-
-cglobal x264_pixel_satd_4x4_mmxext
-cglobal x264_pixel_satd_4x8_mmxext
-cglobal x264_pixel_satd_8x4_mmxext
-cglobal x264_pixel_satd_8x8_mmxext
-cglobal x264_pixel_satd_16x8_mmxext
-cglobal x264_pixel_satd_8x16_mmxext
-cglobal x264_pixel_satd_16x16_mmxext
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_sad_16x16_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_sad_16x16_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm0, mm0
-
- SAD_INC_2x16P
- SAD_INC_2x16P
- SAD_INC_2x16P
- SAD_INC_2x16P
-
- SAD_INC_2x16P
- SAD_INC_2x16P
- SAD_INC_2x16P
- SAD_INC_2x16P
-
- movd eax, mm0
-
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_sad_16x8_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_sad_16x8_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm0, mm0
-
- SAD_INC_2x16P
- SAD_INC_2x16P
- SAD_INC_2x16P
- SAD_INC_2x16P
-
- movd eax, mm0
-
- pop ebx
- ret
-
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_sad_8x16_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_sad_8x16_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm0, mm0
-
- SAD_INC_2x8P
- SAD_INC_2x8P
- SAD_INC_2x8P
- SAD_INC_2x8P
-
- SAD_INC_2x8P
- SAD_INC_2x8P
- SAD_INC_2x8P
- SAD_INC_2x8P
-
- movd eax, mm0
-
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_sad_8x8_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_sad_8x8_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm0, mm0
-
- SAD_INC_2x8P
- SAD_INC_2x8P
- SAD_INC_2x8P
- SAD_INC_2x8P
-
- movd eax, mm0
-
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_sad_8x4_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_sad_8x4_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm0, mm0
-
- SAD_INC_2x8P
- SAD_INC_2x8P
-
- movd eax, mm0
-
- pop ebx
- ret
-
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_sad_4x8_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_sad_4x8_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm0, mm0
-
- SAD_INC_2x4P
- SAD_INC_2x4P
-
- SAD_INC_2x4P
- SAD_INC_2x4P
-
- movd eax, mm0
-
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_sad_4x4_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_sad_4x4_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm0, mm0
-
- SAD_INC_2x4P
- SAD_INC_2x4P
-
- movd eax, mm0
-
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_satd_4x4_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_satd_4x4_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm7, mm7
-
-
- LOAD_DIFF_4P mm0, mm6, mm7, [eax], [ecx]
- LOAD_DIFF_4P mm1, mm6, mm7, [eax+ebx], [ecx+edx]
- LOAD_DIFF_4P mm2, mm6, mm7, [eax+2*ebx], [ecx+2*edx]
- add eax, ebx
- add ecx, edx
- LOAD_DIFF_4P mm3, mm6, mm7, [eax+2*ebx], [ecx+2*edx]
-
- HADAMARD4x4_FIRST
-
- MMX_SUM_MM mm0, mm7
- pop ebx
- ret
-
-
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_satd_4x8_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_satd_4x8_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm7, mm7
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_satd_8x4_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_satd_8x4_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm7, mm7
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_FIRST
-
- mov eax, [esp+ 8] ; pix1
- mov ecx, [esp+16] ; pix2
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_satd_8x8_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_satd_8x8_mmxext:
- push ebx
-
- mov eax, [esp+ 8] ; pix1
- mov ebx, [esp+12] ; stride1
- mov ecx, [esp+16] ; pix2
- mov edx, [esp+20] ; stride2
-
- pxor mm7, mm7
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- mov eax, [esp+ 8] ; pix1
- mov ecx, [esp+16] ; pix2
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_satd_16x8_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_satd_16x8_mmxext:
- push ebx
- push ebp
-
- mov eax, [esp+12] ; pix1
- mov ebx, [esp+16] ; stride1
- mov ecx, [esp+20] ; pix2
- mov edx, [esp+24] ; stride2
-
- pxor mm7, mm7
- xor ebp, ebp
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- mov eax, [esp+12] ; pix1
- mov ecx, [esp+20] ; pix2
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- mov ebp, eax
-
- mov eax, [esp+12] ; pix1
- mov ecx, [esp+20] ; pix2
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 8
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 8
- HADAMARD4x4_NEXT
-
- mov eax, [esp+12] ; pix1
- mov ecx, [esp+20] ; pix2
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- add eax, ebp
-
- pop ebp
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_satd_8x16_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_satd_8x16_mmxext:
- push ebx
- push ebp
-
- mov eax, [esp+12] ; pix1
- mov ebx, [esp+16] ; stride1
- mov ecx, [esp+20] ; pix2
- mov edx, [esp+24] ; stride2
-
- pxor mm7, mm7
- xor ebp, ebp
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- mov ebp, eax
-
- mov eax, [esp+12] ; pix1
- mov ecx, [esp+20] ; pix2
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- add eax, ebp
-
- pop ebp
- pop ebx
- ret
-
-ALIGN 16
-;-----------------------------------------------------------------------------
-; int __cdecl x264_pixel_satd_16x16_mmxext (uint8_t *, int, uint8_t *, int )
-;-----------------------------------------------------------------------------
-x264_pixel_satd_16x16_mmxext:
- push ebx
- push ebp
-
- mov eax, [esp+12] ; pix1
- mov ebx, [esp+16] ; stride1
- mov ecx, [esp+20] ; pix2
- mov edx, [esp+24] ; stride2
-
- pxor mm7, mm7
- xor ebp, ebp
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 0
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- mov ebp, eax
-
- mov eax, [esp+12] ; pix1
- mov ecx, [esp+20] ; pix2
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 4
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- add ebp, eax
-
- mov eax, [esp+12] ; pix1
- mov ecx, [esp+20] ; pix2
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 8
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 8
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 8
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 8
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- add ebp, eax
-
- mov eax, [esp+12] ; pix1
- mov ecx, [esp+20] ; pix2
-
- LOAD_DIFF_INC_4x4 mm0, mm1, mm2, mm3, mm6, mm7, eax, ebx, ecx, edx, 12
- HADAMARD4x4_FIRST
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
- HADAMARD4x4_NEXT
-
- LOAD_DIFF_INC_4x4 mm1, mm2, mm3, mm4, mm6, mm7, eax, ebx, ecx, edx, 12
- HADAMARD4x4_NEXT
-
- MMX_SUM_MM mm0, mm7
- add eax, ebp
-
- pop ebp
- pop ebx
- ret
-
+++ /dev/null
-/*****************************************************************************
- * mc.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: pixel.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _I386_PIXEL_H
-#define _I386_PIXEL_H 1
-
-int x264_pixel_sad_16x16_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_sad_16x8_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_sad_8x16_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_sad_8x8_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_sad_8x4_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_sad_4x8_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_sad_4x4_mmxext( uint8_t *, int, uint8_t *, int );
-
-int x264_pixel_satd_16x16_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_satd_16x8_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_satd_8x16_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_satd_8x8_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_satd_8x4_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_satd_4x8_mmxext( uint8_t *, int, uint8_t *, int );
-int x264_pixel_satd_4x4_mmxext( uint8_t *, int, uint8_t *, int );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * predict.c: h264 encoder
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: predict.c,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-/* XXX predict4x4 are inspired from ffmpeg h264 decoder
- */
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-#include <stdarg.h>
-
-#include "x264.h" /* for keyword inline */
-#include "../predict.h"
-#include "predict.h"
-
-static inline int clip_uint8( int a )
-{
- if (a&(~255))
- return (-a)>>31;
- else
- return a;
-}
-
-/****************************************************************************
- * 16x16 prediction for intra block DC, H, V, P
- ****************************************************************************/
-static void predict_16x16_dc( uint8_t *src, int i_stride )
-{
- uint32_t dc = 0;
- int i;
-
- /* calculate DC value */
- for( i = 0; i < 16; i++ )
- {
- dc += src[-1 + i * i_stride];
- dc += src[i - i_stride];
- }
- dc = (( dc + 16 ) >> 5) * 0x01010101;
-
- for( i = 0; i < 16; i++ )
- {
- uint32_t *p = (uint32_t*)src;
-
- *p++ = dc;
- *p++ = dc;
- *p++ = dc;
- *p++ = dc;
-
- src += i_stride;
- }
-}
-static void predict_16x16_dc_left( uint8_t *src, int i_stride )
-{
- uint32_t dc = 0;
- int i;
-
- for( i = 0; i < 16; i++ )
- {
- dc += src[-1 + i * i_stride];
- }
- dc = (( dc + 8 ) >> 4) * 0x01010101;
-
- for( i = 0; i < 16; i++ )
- {
- uint32_t *p = (uint32_t*)src;
-
- *p++ = dc;
- *p++ = dc;
- *p++ = dc;
- *p++ = dc;
-
- src += i_stride;
- }
-}
-static void predict_16x16_dc_top( uint8_t *src, int i_stride )
-{
- uint32_t dc = 0;
- int i;
-
- for( i = 0; i < 16; i++ )
- {
- dc += src[i - i_stride];
- }
- dc = (( dc + 8 ) >> 4) * 0x01010101;
-
- for( i = 0; i < 16; i++ )
- {
- uint32_t *p = (uint32_t*)src;
-
- *p++ = dc;
- *p++ = dc;
- *p++ = dc;
- *p++ = dc;
-
- src += i_stride;
- }
-}
-static void predict_16x16_dc_128( uint8_t *src, int i_stride )
-{
- int i;
-
- for( i = 0; i < 16; i++ )
- {
- uint32_t *p = (uint32_t*)src;
-
- *p++ = 0x80808080;
- *p++ = 0x80808080;
- *p++ = 0x80808080;
- *p++ = 0x80808080;
-
- src += i_stride;
- }
-}
-static void predict_16x16_h( uint8_t *src, int i_stride )
-{
- int i;
-
- for( i = 0; i < 16; i++ )
- {
- const uint32_t v = 0x01010101 * src[-1];
- uint32_t *p = (uint32_t*)src;
-
- *p++ = v;
- *p++ = v;
- *p++ = v;
- *p++ = v;
-
- src += i_stride;
-
- }
-}
-static void predict_16x16_v( uint8_t *src, int i_stride )
-{
- int i;
-
- asm volatile(
- "movq (%0), %%mm0\n"
- "movq 8(%0), %%mm1\n" :: "r"(&src[-i_stride]) );
-
- for( i = 0; i < 16; i++ )
- {
- asm volatile(
- "movq %%mm0, (%0)\n"
- "movq %%mm1, 8(%0)\n" :: "r"(src) );
- src += i_stride;
- }
-}
-
-/****************************************************************************
- * 8x8 prediction for intra chroma block DC, H, V, P
- ****************************************************************************/
-static void predict_8x8_dc_128( uint8_t *src, int i_stride )
-{
- int y;
-
- for( y = 0; y < 8; y++ )
- {
- uint32_t *p = (uint32_t*)src;
-
- *p++ = 0x80808080;
- *p++ = 0x80808080;
-
- src += i_stride;
- }
-}
-static void predict_8x8_dc_left( uint8_t *src, int i_stride )
-{
- int y;
- uint32_t dc0 = 0, dc1 = 0;
-
- for( y = 0; y < 4; y++ )
- {
- dc0 += src[y * i_stride - 1];
- dc1 += src[(y+4) * i_stride - 1];
- }
- dc0 = (( dc0 + 2 ) >> 2)*0x01010101;
- dc1 = (( dc1 + 2 ) >> 2)*0x01010101;
-
- for( y = 0; y < 4; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p++ = dc0;
- *p++ = dc0;
-
- src += i_stride;
- }
- for( y = 0; y < 4; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p++ = dc1;
- *p++ = dc1;
-
- src += i_stride;
- }
-
-}
-static void predict_8x8_dc_top( uint8_t *src, int i_stride )
-{
- int y, x;
- uint32_t dc0 = 0, dc1 = 0;
-
- for( x = 0; x < 4; x++ )
- {
- dc0 += src[x - i_stride];
- dc1 += src[x + 4 - i_stride];
- }
- dc0 = (( dc0 + 2 ) >> 2)*0x01010101;
- dc1 = (( dc1 + 2 ) >> 2)*0x01010101;
-
- for( y = 0; y < 8; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p++ = dc0;
- *p++ = dc1;
-
- src += i_stride;
- }
-}
-static void predict_8x8_dc( uint8_t *src, int i_stride )
-{
- int y;
- int s0 = 0, s1 = 0, s2 = 0, s3 = 0;
- uint32_t dc0, dc1, dc2, dc3;
- int i;
-
- /* First do :
- s0 s1
- s2
- s3
- */
- for( i = 0; i < 4; i++ )
- {
- s0 += src[i - i_stride];
- s1 += src[i + 4 - i_stride];
- s2 += src[-1 + i * i_stride];
- s3 += src[-1 + (i+4)*i_stride];
- }
- /* now calculate
- dc0 dc1
- dc2 dc3
- */
- dc0 = (( s0 + s2 + 4 ) >> 3)*0x01010101;
- dc1 = (( s1 + 2 ) >> 2)*0x01010101;
- dc2 = (( s3 + 2 ) >> 2)*0x01010101;
- dc3 = (( s1 + s3 + 4 ) >> 3)*0x01010101;
-
- for( y = 0; y < 4; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p++ = dc0;
- *p++ = dc1;
-
- src += i_stride;
- }
-
- for( y = 0; y < 4; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p++ = dc2;
- *p++ = dc3;
-
- src += i_stride;
- }
-}
-
-static void predict_8x8_h( uint8_t *src, int i_stride )
-{
- int i;
-
- for( i = 0; i < 8; i++ )
- {
- uint32_t v = 0x01010101 * src[-1];
- uint32_t *p = (uint32_t*)src;
-
- *p++ = v;
- *p++ = v;
-
- src += i_stride;
- }
-}
-static void predict_8x8_v( uint8_t *src, int i_stride )
-{
- int i;
-
- asm volatile( "movq (%0), %%mm0\n" :: "r"(&src[-i_stride]) );
-
- for( i = 0; i < 8; i++ )
- {
- asm volatile( "movq %%mm0, (%0)\n" :: "r"(src) );
- src += i_stride;
- }
-}
-
-
-/****************************************************************************
- * 4x4 prediction for intra luma block DC, H, V, P
- ****************************************************************************/
-static void predict_4x4_dc_128( uint8_t *src, int i_stride )
-{
- int y;
- for( y = 0; y < 4; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p = 0x80808080;
-
- src += i_stride;
- }
-}
-static void predict_4x4_dc_left( uint8_t *src, int i_stride )
-{
- int y;
- uint32_t dc = (( src[-1+0*i_stride] + src[-1+i_stride]+
- src[-1+2*i_stride] + src[-1+3*i_stride] + 2 ) >> 2)*0x01010101;
-
- for( y = 0; y < 4; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p = dc;
-
- src += i_stride;
- }
-}
-static void predict_4x4_dc_top( uint8_t *src, int i_stride )
-{
- int y;
- uint32_t dc = (( src[0 - i_stride] + src[1 - i_stride] +
- src[2 - i_stride] + src[3 - i_stride] + 2 ) >> 2)*0x01010101;
-
- for( y = 0; y < 4; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p = dc;
- src += i_stride;
- }
-}
-static void predict_4x4_dc( uint8_t *src, int i_stride )
-{
- int y;
- uint32_t dc = (( src[-1+0*i_stride] + src[-1+i_stride]+
- src[-1+2*i_stride] + src[-1+3*i_stride] +
- src[0 - i_stride] + src[1 - i_stride] +
- src[2 - i_stride] + src[3 - i_stride] + 4 ) >> 3)*0x01010101;
-
- for( y = 0; y < 4; y++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p = dc;
-
- src += i_stride;
- }
-}
-static void predict_4x4_h( uint8_t *src, int i_stride )
-{
- int i;
-
- for( i = 0; i < 4; i++ )
- {
- uint32_t *p = (uint32_t*)src;
- *p = 0x01010101*src[-1];
-
- src += i_stride;
- }
-}
-static void predict_4x4_v( uint8_t *src, int i_stride )
-{
- uint32_t top = *((uint32_t*)&src[-i_stride]);
- int i;
-
- for( i = 0; i < 4; i++ )
- {
- uint32_t *p = (uint32_t*)src;
-
- *p = top;
-
- src += i_stride;
- }
-}
-
-/****************************************************************************
- * Exported functions:
- ****************************************************************************/
-void x264_predict_16x16_init_mmxext( x264_predict_t pf[7] )
-{
- pf[I_PRED_16x16_V ] = predict_16x16_v;
- pf[I_PRED_16x16_H ] = predict_16x16_h;
- pf[I_PRED_16x16_DC] = predict_16x16_dc;
- pf[I_PRED_16x16_DC_LEFT]= predict_16x16_dc_left;
- pf[I_PRED_16x16_DC_TOP ]= predict_16x16_dc_top;
- pf[I_PRED_16x16_DC_128 ]= predict_16x16_dc_128;
-}
-
-void x264_predict_8x8_init_mmxext( x264_predict_t pf[7] )
-{
- pf[I_PRED_CHROMA_V ] = predict_8x8_v;
- pf[I_PRED_CHROMA_H ] = predict_8x8_h;
- pf[I_PRED_CHROMA_DC] = predict_8x8_dc;
- pf[I_PRED_CHROMA_DC_LEFT]= predict_8x8_dc_left;
- pf[I_PRED_CHROMA_DC_TOP ]= predict_8x8_dc_top;
- pf[I_PRED_CHROMA_DC_128 ]= predict_8x8_dc_128;
-}
-
-void x264_predict_4x4_init_mmxext( x264_predict_t pf[12] )
-{
- pf[I_PRED_4x4_V] = predict_4x4_v;
- pf[I_PRED_4x4_H] = predict_4x4_h;
- pf[I_PRED_4x4_DC] = predict_4x4_dc;
- pf[I_PRED_4x4_DC_LEFT]= predict_4x4_dc_left;
- pf[I_PRED_4x4_DC_TOP] = predict_4x4_dc_top;
- pf[I_PRED_4x4_DC_128] = predict_4x4_dc_128;
-}
-
+++ /dev/null
-/*****************************************************************************
- * predict.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: predict.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _I386_PREDICT_H
-#define _I386_PREDICT_H 1
-
-void x264_predict_16x16_init_mmxext ( x264_predict_t pf[7] );
-void x264_predict_8x8_init_mmxext ( x264_predict_t pf[7] );
-void x264_predict_4x4_init_mmxext ( x264_predict_t pf[12] );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * macroblock.c: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: macroblock.c,v 1.1 2004/06/03 19:27:06 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 "common.h"
-#include "macroblock.h"
-
-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 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} }
-};
-
-#if 0
-static const int i_chroma_qp_table[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
-};
-#endif
-
-int x264_mb_predict_intra4x4_mode( x264_t *h, int idx )
-{
- const int ma = h->mb.cache.intra4x4_pred_mode[x264_scan8[idx] - 1];
- const int mb = h->mb.cache.intra4x4_pred_mode[x264_scan8[idx] - 8];
- const int m = X264_MIN( ma, mb );
-
- if( m < 0 )
- return I_PRED_4x4_DC;
-
- return m;
-}
-
-int x264_mb_predict_non_zero_code( x264_t *h, int idx )
-{
- const int za = h->mb.cache.non_zero_count[x264_scan8[idx] - 1];
- const int zb = h->mb.cache.non_zero_count[x264_scan8[idx] - 8];
-
- int i_ret = za + zb;
-
- if( i_ret < 0x80 )
- {
- i_ret = ( i_ret + 1 ) >> 1;
- }
- return i_ret & 0x7f;
-}
-
-/****************************************************************************
- * Scan and Quant functions
- ****************************************************************************/
-void x264_mb_dequant_2x2_dc( int16_t dct[2][2], int i_qscale )
-{
- const int i_qbits = i_qscale/6 - 1;
-
- if( i_qbits >= 0 )
- {
- const int i_dmf = dequant_mf[i_qscale%6][0][0] << i_qbits;
-
- dct[0][0] = dct[0][0] * i_dmf;
- dct[0][1] = dct[0][1] * i_dmf;
- dct[1][0] = dct[1][0] * i_dmf;
- dct[1][1] = dct[1][1] * i_dmf;
- }
- else
- {
- const int i_dmf = dequant_mf[i_qscale%6][0][0];
-
- dct[0][0] = ( dct[0][0] * i_dmf ) >> 1;
- dct[0][1] = ( dct[0][1] * i_dmf ) >> 1;
- dct[1][0] = ( dct[1][0] * i_dmf ) >> 1;
- dct[1][1] = ( dct[1][1] * i_dmf ) >> 1;
- }
-}
-
-void x264_mb_dequant_4x4_dc( int16_t dct[4][4], int i_qscale )
-{
- const int i_qbits = i_qscale/6 - 2;
- int x,y;
-
- if( i_qbits >= 0 )
- {
- const int i_dmf = dequant_mf[i_qscale%6][0][0] << i_qbits;
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- dct[y][x] = dct[y][x] * i_dmf;
- }
- }
- }
- else
- {
- const int i_dmf = dequant_mf[i_qscale%6][0][0];
- const int f = 1 << ( 1 + i_qbits );
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- dct[y][x] = ( dct[y][x] * i_dmf + f ) >> (-i_qbits);
- }
- }
- }
-}
-
-void x264_mb_dequant_4x4( int16_t dct[4][4], int i_qscale )
-{
- const int i_mf = i_qscale%6;
- const int i_qbits = i_qscale/6;
- int y;
-
- for( y = 0; y < 4; y++ )
- {
- dct[y][0] = ( dct[y][0] * dequant_mf[i_mf][y][0] ) << i_qbits;
- dct[y][1] = ( dct[y][1] * dequant_mf[i_mf][y][1] ) << i_qbits;
- dct[y][2] = ( dct[y][2] * dequant_mf[i_mf][y][2] ) << i_qbits;
- dct[y][3] = ( dct[y][3] * dequant_mf[i_mf][y][3] ) << i_qbits;
- }
-}
-
-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;
-}
-
-void x264_mb_predict_mv( x264_t *h, int i_list, int idx, int i_width, int mvp[2] )
-{
- const int i8 = x264_scan8[idx];
- const int i_ref= h->mb.cache.ref[i_list][i8];
- int i_refa = h->mb.cache.ref[i_list][i8 - 1];
- int16_t *mv_a = h->mb.cache.mv[i_list][i8 - 1];
- int i_refb = h->mb.cache.ref[i_list][i8 - 8];
- int16_t *mv_b = h->mb.cache.mv[i_list][i8 - 8];
- int i_refc = h->mb.cache.ref[i_list][i8 - 8 + i_width ];
- int16_t *mv_c = h->mb.cache.mv[i_list][i8 - 8 + i_width];
-
- int i_count;
-
- if( (idx&0x03) == 3 || ( i_width == 2 && (idx&0x3) == 2 )|| i_refc == -2 )
- {
- i_refc = h->mb.cache.ref[i_list][i8 - 8 - 1];
- mv_c = h->mb.cache.mv[i_list][i8 - 8 - 1];
- }
-
- if( h->mb.i_partition == D_16x8 )
- {
- if( idx == 0 && i_refb == i_ref )
- {
- mvp[0] = mv_b[0];
- mvp[1] = mv_b[1];
- return;
- }
- else if( idx != 0 && i_refa == i_ref )
- {
- mvp[0] = mv_a[0];
- mvp[1] = mv_a[1];
- return;
- }
- }
- else if( h->mb.i_partition == D_8x16 )
- {
- if( idx == 0 && i_refa == i_ref )
- {
- mvp[0] = mv_a[0];
- mvp[1] = mv_a[1];
- return;
- }
- else if( idx != 0 && i_refc == i_ref )
- {
- mvp[0] = mv_c[0];
- mvp[1] = mv_c[1];
- return;
- }
- }
-
- i_count = 0;
- if( i_refa == i_ref ) i_count++;
- if( i_refb == i_ref ) i_count++;
- if( i_refc == i_ref ) i_count++;
-
- if( i_count > 1 )
- {
- mvp[0] = x264_median( mv_a[0], mv_b[0], mv_c[0] );
- mvp[1] = x264_median( mv_a[1], mv_b[1], mv_c[1] );
- }
- else if( i_count == 1 )
- {
- if( i_refa == i_ref )
- {
- mvp[0] = mv_a[0];
- mvp[1] = mv_a[1];
- }
- else if( i_refb == i_ref )
- {
- mvp[0] = mv_b[0];
- mvp[1] = mv_b[1];
- }
- else
- {
- mvp[0] = mv_c[0];
- mvp[1] = mv_c[1];
- }
- }
- else if( i_refb == -2 && i_refc == -2 && i_refa != -2 )
- {
- mvp[0] = mv_a[0];
- mvp[1] = mv_a[1];
- }
- else
- {
- mvp[0] = x264_median( mv_a[0], mv_b[0], mv_c[0] );
- mvp[1] = x264_median( mv_a[1], mv_b[1], mv_c[1] );
- }
-}
-
-void x264_mb_predict_mv_16x16( x264_t *h, int i_list, int i_ref, int mvp[2] )
-{
- int i_refa = h->mb.cache.ref[i_list][X264_SCAN8_0 - 1];
- int16_t *mv_a = h->mb.cache.mv[i_list][X264_SCAN8_0 - 1];
- int i_refb = h->mb.cache.ref[i_list][X264_SCAN8_0 - 8];
- int16_t *mv_b = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8];
- int i_refc = h->mb.cache.ref[i_list][X264_SCAN8_0 - 8 + 4];
- int16_t *mv_c = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8 + 4];
-
- int i_count;
-
- if( i_refc == -2 )
- {
- i_refc = h->mb.cache.ref[i_list][X264_SCAN8_0 - 8 - 1];
- mv_c = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8 - 1];
- }
-
- i_count = 0;
- if( i_refa == i_ref ) i_count++;
- if( i_refb == i_ref ) i_count++;
- if( i_refc == i_ref ) i_count++;
-
- if( i_count > 1 )
- {
- mvp[0] = x264_median( mv_a[0], mv_b[0], mv_c[0] );
- mvp[1] = x264_median( mv_a[1], mv_b[1], mv_c[1] );
- }
- else if( i_count == 1 )
- {
- if( i_refa == i_ref )
- {
- mvp[0] = mv_a[0];
- mvp[1] = mv_a[1];
- }
- else if( i_refb == i_ref )
- {
- mvp[0] = mv_b[0];
- mvp[1] = mv_b[1];
- }
- else
- {
- mvp[0] = mv_c[0];
- mvp[1] = mv_c[1];
- }
- }
- else if( i_refb == -2 && i_refc == -2 && i_refa != -2 )
- {
- mvp[0] = mv_a[0];
- mvp[1] = mv_a[1];
- }
- else
- {
- mvp[0] = x264_median( mv_a[0], mv_b[0], mv_c[0] );
- mvp[1] = x264_median( mv_a[1], mv_b[1], mv_c[1] );
- }
-}
-
-
-void x264_mb_predict_mv_pskip( x264_t *h, int mv[2] )
-{
- int i_refa = h->mb.cache.ref[0][X264_SCAN8_0 - 1];
- int i_refb = h->mb.cache.ref[0][X264_SCAN8_0 - 8];
- int16_t *mv_a = h->mb.cache.mv[0][X264_SCAN8_0 - 1];
- int16_t *mv_b = h->mb.cache.mv[0][X264_SCAN8_0 - 8];
-
- if( i_refa == -2 || i_refb == -2 ||
- ( i_refa == 0 && mv_a[0] == 0 && mv_a[1] == 0 ) ||
- ( i_refb == 0 && mv_b[0] == 0 && mv_b[1] == 0 ) )
- {
- mv[0] = mv[1] = 0;
- }
- else
- {
- x264_mb_predict_mv_16x16( h, 0, 0, mv );
- }
-}
-
-void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int mvc[4][2], int *i_mvc )
-{
- int16_t (*mvr)[2] = h->mb.mvr[i_list][i_ref];
-
- int i = 0;
- if( h->mb.i_mb_x > 0 )
- {
- int i_mb_l = h->mb.i_mb_xy - 1;
- mvc[i][0] = mvr[i_mb_l][0];
- mvc[i][1] = mvr[i_mb_l][1];
- i++;
- }
- if( h->mb.i_mb_y > 0 )
- {
- int i_mb_t = h->mb.i_mb_xy - h->mb.i_mb_stride;
- mvc[i][0] = mvr[i_mb_t][0];
- mvc[i][1] = mvr[i_mb_t][1];
- i++;
-
- if( h->mb.i_mb_x > 0 )
- {
- mvc[i][0] = mvr[i_mb_t - 1][0];
- mvc[i][1] = mvr[i_mb_t - 1][1];
- i++;
- }
- if( h->mb.i_mb_x < h->mb.i_mb_stride - 1 )
- {
- mvc[i][0] = mvr[i_mb_t + 1][0];
- mvc[i][1] = mvr[i_mb_t + 1][1];
- i++;
- }
- }
- *i_mvc = i;
-}
-
-static inline void x264_mb_mc_0xywh( x264_t *h, int x, int y, int width, int height )
-{
- const int i8 = x264_scan8[0]+x+8*y;
- const int i_ref = h->mb.cache.ref[0][i8];
- const int mvx = h->mb.cache.mv[0][i8][0];
- const int mvy = h->mb.cache.mv[0][i8][1];
-
- h->mc[MC_LUMA]( &h->mb.pic.p_fref[0][i_ref][0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
- &h->mb.pic.p_fdec[0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
- mvx, mvy, 4*width, 4*height );
-
- h->mc[MC_CHROMA]( &h->mb.pic.p_fref[0][i_ref][1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
- &h->mb.pic.p_fdec[1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
- mvx, mvy, 2*width, 2*height );
-
- h->mc[MC_CHROMA]( &h->mb.pic.p_fref[0][i_ref][2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
- &h->mb.pic.p_fdec[2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
- mvx, mvy, 2*width, 2*height );
-}
-static inline void x264_mb_mc_1xywh( x264_t *h, int x, int y, int width, int height )
-{
- const int i8 = x264_scan8[0]+x+8*y;
- const int i_ref = h->mb.cache.ref[1][i8];
- const int mvx = h->mb.cache.mv[1][i8][0];
- const int mvy = h->mb.cache.mv[1][i8][1];
-
- h->mc[MC_LUMA]( &h->mb.pic.p_fref[1][i_ref][0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
- &h->mb.pic.p_fdec[0][4*y *h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
- mvx, mvy, 4*width, 4*height );
-
- h->mc[MC_CHROMA]( &h->mb.pic.p_fref[1][i_ref][1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
- &h->mb.pic.p_fdec[1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
- mvx, mvy, 2*width, 2*height );
-
- h->mc[MC_CHROMA]( &h->mb.pic.p_fref[1][i_ref][2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
- &h->mb.pic.p_fdec[2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
- mvx, mvy, 2*width, 2*height );
-}
-
-static inline void x264_mb_mc_01xywh( x264_t *h, int x, int y, int width, int height )
-{
- const int i8 = x264_scan8[0]+x+8*y;
-
- const int i_ref0 = h->mb.cache.ref[0][i8];
- const int mvx0 = h->mb.cache.mv[0][i8][0];
- const int mvy0 = h->mb.cache.mv[0][i8][1];
-
- const int i_ref1 = h->mb.cache.ref[1][i8];
- const int mvx1 = h->mb.cache.mv[1][i8][0];
- const int mvy1 = h->mb.cache.mv[1][i8][1];
- DECLARE_ALIGNED( uint8_t, tmp[16*16], 16 );
- int i_mode = 0;
-
- if( width == 4 && height == 4 ) i_mode = PIXEL_16x16;
- else if( width == 4 && height == 2 ) i_mode = PIXEL_16x8;
- else if( width == 2 && height == 4 ) i_mode = PIXEL_8x16;
- else if( width == 2 && height == 2 ) i_mode = PIXEL_8x8;
- else if( width == 2 && height == 1 ) i_mode = PIXEL_8x4;
- else if( width == 1 && height == 2 ) i_mode = PIXEL_4x8;
- else if( width == 1 && height == 1 ) i_mode = PIXEL_4x4;
-
- h->mc[MC_LUMA]( &h->mb.pic.p_fref[0][i_ref0][0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
- &h->mb.pic.p_fdec[0][4*y *h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
- mvx0, mvy0, 4*width, 4*height );
- h->mc[MC_CHROMA]( &h->mb.pic.p_fref[0][i_ref0][1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
- &h->mb.pic.p_fdec[1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
- mvx0, mvy0, 2*width, 2*height );
- h->mc[MC_CHROMA]( &h->mb.pic.p_fref[0][i_ref0][2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
- &h->mb.pic.p_fdec[2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
- mvx0, mvy0, 2*width, 2*height );
-
-
- h->mc[MC_LUMA]( &h->mb.pic.p_fref[1][i_ref1][0][4*y * h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0],
- tmp, 16, mvx1, mvy1, 4*width, 4*height );
- h->pixf.avg[i_mode]( &h->mb.pic.p_fdec[0][4*y *h->mb.pic.i_stride[0]+4*x], h->mb.pic.i_stride[0], tmp, 16 );
-
- h->mc[MC_CHROMA]( &h->mb.pic.p_fref[1][i_ref1][1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
- tmp, 16, mvx1, mvy1, 2*width, 2*height );
- h->pixf.avg[i_mode]( &h->mb.pic.p_fdec[1][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1], tmp, 16 );
-
- h->mc[MC_CHROMA]( &h->mb.pic.p_fref[1][i_ref1][2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2],
- tmp, 16, mvx1, mvy1, 2*width, 2*height );
- h->pixf.avg[i_mode]( &h->mb.pic.p_fdec[2][2*y*h->mb.pic.i_stride[2]+2*x], h->mb.pic.i_stride[2], tmp, 16 );
-}
-
-
-void x264_mb_mc( x264_t *h )
-{
- if( h->mb.i_type == P_L0 )
- {
- if( h->mb.i_partition == D_16x16 )
- {
- x264_mb_mc_0xywh( h, 0, 0, 4, 4 );
- }
- else if( h->mb.i_partition == D_16x8 )
- {
- x264_mb_mc_0xywh( h, 0, 0, 4, 2 );
- x264_mb_mc_0xywh( h, 0, 2, 4, 2 );
- }
- else if( h->mb.i_partition == D_8x16 )
- {
- x264_mb_mc_0xywh( h, 0, 0, 2, 4 );
- x264_mb_mc_0xywh( h, 2, 0, 2, 4 );
- }
- }
- else if( h->mb.i_type == P_8x8 )
- {
- int i;
- for( i = 0; i < 4; i++ )
- {
- const int x = 2*(i%2);
- const int y = 2*(i/2);
- switch( h->mb.i_sub_partition[i] )
- {
- case D_L0_8x8:
- x264_mb_mc_0xywh( h, x, y, 2, 2 );
- break;
- case D_L0_8x4:
- x264_mb_mc_0xywh( h, x, y+0, 2, 1 );
- x264_mb_mc_0xywh( h, x, y+1, 2, 1 );
- break;
- case D_L0_4x8:
- x264_mb_mc_0xywh( h, x+0, y, 1, 2 );
- x264_mb_mc_0xywh( h, x+1, y, 1, 2 );
- break;
- case D_L0_4x4:
- x264_mb_mc_0xywh( h, x+0, y+0, 1, 1 );
- x264_mb_mc_0xywh( h, x+1, y+0, 1, 1 );
- x264_mb_mc_0xywh( h, x+0, y+1, 1, 1 );
- x264_mb_mc_0xywh( h, x+1, y+1, 1, 1 );
- break;
- }
- }
- }
- else if( h->mb.i_type == B_8x8 || h->mb.i_type == B_DIRECT )
- {
- x264_log( h, X264_LOG_ERROR, "mc_luma with unsupported mb\n" );
- return;
- }
- else /* B_*x* */
- {
- int b_list0[2];
- int b_list1[2];
-
- int i;
-
- /* init ref list utilisations */
- for( i = 0; i < 2; i++ )
- {
- b_list0[i] = x264_mb_type_list0_table[h->mb.i_type][i];
- b_list1[i] = x264_mb_type_list1_table[h->mb.i_type][i];
- }
- if( h->mb.i_partition == D_16x16 )
- {
- if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 4, 4 );
- else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 4, 4 );
- else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 4, 4 );
- }
- else if( h->mb.i_partition == D_16x8 )
- {
- if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 4, 2 );
- else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 4, 2 );
- else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 4, 2 );
-
- if( b_list0[1] && b_list1[1] ) x264_mb_mc_01xywh( h, 0, 2, 4, 2 );
- else if( b_list0[1] ) x264_mb_mc_0xywh ( h, 0, 2, 4, 2 );
- else if( b_list1[1] ) x264_mb_mc_1xywh ( h, 0, 2, 4, 2 );
- }
- else if( h->mb.i_partition == D_8x16 )
- {
- if( b_list0[0] && b_list1[0] ) x264_mb_mc_01xywh( h, 0, 0, 2, 4 );
- else if( b_list0[0] ) x264_mb_mc_0xywh ( h, 0, 0, 2, 4 );
- else if( b_list1[0] ) x264_mb_mc_1xywh ( h, 0, 0, 2, 4 );
-
- if( b_list0[1] && b_list1[1] ) x264_mb_mc_01xywh( h, 2, 0, 2, 4 );
- else if( b_list0[1] ) x264_mb_mc_0xywh ( h, 2, 0, 2, 4 );
- else if( b_list1[1] ) x264_mb_mc_1xywh ( h, 2, 0, 2, 4 );
- }
- }
-}
-
-void x264_macroblock_cache_init( x264_t *h )
-{
- int i, j;
- int i_mb_count = h->sps->i_mb_width * h->sps->i_mb_height;
-
- h->mb.i_mb_stride = h->sps->i_mb_width;
-
- h->mb.type= x264_malloc( i_mb_count * sizeof( int8_t) );
- h->mb.qp = x264_malloc( i_mb_count * sizeof( int8_t) );
- h->mb.cbp = x264_malloc( i_mb_count * sizeof( int16_t) );
-
- /* 0 -> 3 top(4), 4 -> 6 : left(3) */
- h->mb.intra4x4_pred_mode = x264_malloc( i_mb_count * 7 * sizeof( int8_t ) );
-
- /* all coeffs */
- h->mb.non_zero_count = x264_malloc( i_mb_count * 24 * sizeof( uint8_t ) );
-
- h->mb.mv[0] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
- h->mb.mv[1] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
- h->mb.ref[0] = x264_malloc( 4 * i_mb_count * sizeof( int16_t ) );
- h->mb.ref[1] = x264_malloc( 4 * i_mb_count * sizeof( int16_t ) );
-
- if( h->param.b_cabac )
- {
- h->mb.chroma_pred_mode = x264_malloc( i_mb_count * sizeof( int8_t) );
- h->mb.mvd[0] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
- h->mb.mvd[1] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
- }
-
- for( i=0; i<2; i++ )
- for( j=0; j<16; j++ ) /* FIXME: alloc no more than param.i_frame_reference */
- h->mb.mvr[i][j] = x264_malloc( 2 * i_mb_count * sizeof( int16_t ) );
-
- /* init with not avaiable (for top right idx=7,15) */
- memset( h->mb.cache.ref[0], -2, X264_SCAN8_SIZE * sizeof( int8_t ) );
- memset( h->mb.cache.ref[1], -2, X264_SCAN8_SIZE * sizeof( int8_t ) );
-}
-void x264_macroblock_cache_end( x264_t *h )
-{
- int i, j;
- for( i=0; i<2; i++ )
- for( j=0; j<16; j++ )
- x264_free( h->mb.mvr[i][j] );
- if( h->param.b_cabac )
- {
- x264_free( h->mb.chroma_pred_mode );
- x264_free( h->mb.mvd[0] );
- x264_free( h->mb.mvd[1] );
- }
- x264_free( h->mb.mv[0] );
- x264_free( h->mb.mv[1] );
- x264_free( h->mb.ref[0] );
- x264_free( h->mb.ref[1] );
- x264_free( h->mb.intra4x4_pred_mode );
- x264_free( h->mb.non_zero_count );
- x264_free( h->mb.cbp );
- x264_free( h->mb.qp );
- x264_free( h->mb.type );
-}
-
-
-void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
-{
- const int i_mb_4x4 = 16 * h->mb.i_mb_stride *i_mb_y + 4 * i_mb_x;
- const int i_mb_8x8 = 4 * h->mb.i_mb_stride *i_mb_y + 2 * i_mb_x;
-
- int i_top_xy = -1;
- int i_left_xy = -1;
- int i_top_type = -1; /* gcc warn */
- int i_left_type= -1;
-
- int i;
-
- /* init index */
- h->mb.i_mb_x = i_mb_x;
- h->mb.i_mb_y = i_mb_y;
- h->mb.i_mb_xy = i_mb_y * h->mb.i_mb_stride + i_mb_x;
- h->mb.i_neighbour = 0;
-
- /* load picture pointers */
- for( i = 0; i < 3; i++ )
- {
- const int w = (i == 0 ? 16 : 8);
- const int i_stride = h->fdec->i_stride[i];
- int j;
-
- h->mb.pic.i_stride[i] = i_stride;
-
- h->mb.pic.p_fenc[i] = &h->fenc->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
-
- h->mb.pic.p_fdec[i] = &h->fdec->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
-
- for( j = 0; j < h->i_ref0; j++ )
- {
- h->mb.pic.p_fref[0][j][i] = &h->fref0[j]->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
- }
- for( j = 0; j < h->i_ref1; j++ )
- {
- h->mb.pic.p_fref[1][j][i] = &h->fref1[j]->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
- }
- }
-
- /* load cache */
- if( i_mb_y > 0 )
- {
- i_top_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
- i_top_type= h->mb.type[i_top_xy];
-
- h->mb.i_neighbour |= MB_TOP;
-
- /* load intra4x4 */
- h->mb.cache.intra4x4_pred_mode[x264_scan8[0] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][0];
- h->mb.cache.intra4x4_pred_mode[x264_scan8[1] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][1];
- h->mb.cache.intra4x4_pred_mode[x264_scan8[4] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][2];
- h->mb.cache.intra4x4_pred_mode[x264_scan8[5] - 8] = h->mb.intra4x4_pred_mode[i_top_xy][3];
-
- /* load non_zero_count */
- h->mb.cache.non_zero_count[x264_scan8[0] - 8] = h->mb.non_zero_count[i_top_xy][10];
- h->mb.cache.non_zero_count[x264_scan8[1] - 8] = h->mb.non_zero_count[i_top_xy][11];
- h->mb.cache.non_zero_count[x264_scan8[4] - 8] = h->mb.non_zero_count[i_top_xy][14];
- h->mb.cache.non_zero_count[x264_scan8[5] - 8] = h->mb.non_zero_count[i_top_xy][15];
-
- h->mb.cache.non_zero_count[x264_scan8[16+0] - 8] = h->mb.non_zero_count[i_top_xy][16+2];
- h->mb.cache.non_zero_count[x264_scan8[16+1] - 8] = h->mb.non_zero_count[i_top_xy][16+3];
-
- h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 8] = h->mb.non_zero_count[i_top_xy][16+4+2];
- h->mb.cache.non_zero_count[x264_scan8[16+4+1] - 8] = h->mb.non_zero_count[i_top_xy][16+4+3];
- }
- else
- {
- /* load intra4x4 */
- h->mb.cache.intra4x4_pred_mode[x264_scan8[0] - 8] =
- h->mb.cache.intra4x4_pred_mode[x264_scan8[1] - 8] =
- h->mb.cache.intra4x4_pred_mode[x264_scan8[4] - 8] =
- h->mb.cache.intra4x4_pred_mode[x264_scan8[5] - 8] = -1;
-
- /* load non_zero_count */
- h->mb.cache.non_zero_count[x264_scan8[0] - 8] =
- h->mb.cache.non_zero_count[x264_scan8[1] - 8] =
- h->mb.cache.non_zero_count[x264_scan8[4] - 8] =
- h->mb.cache.non_zero_count[x264_scan8[5] - 8] =
- h->mb.cache.non_zero_count[x264_scan8[16+0] - 8] =
- h->mb.cache.non_zero_count[x264_scan8[16+1] - 8] =
- h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 8] =
- h->mb.cache.non_zero_count[x264_scan8[16+4+1] - 8] = 0x80;
-
- }
-
- if( i_mb_x > 0 )
- {
- i_left_xy = h->mb.i_mb_xy - 1;
- i_left_type= h->mb.type[i_left_xy];
-
- h->mb.i_neighbour |= MB_LEFT;
-
- /* load intra4x4 */
- h->mb.cache.intra4x4_pred_mode[x264_scan8[0 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][4];
- h->mb.cache.intra4x4_pred_mode[x264_scan8[2 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][5];
- h->mb.cache.intra4x4_pred_mode[x264_scan8[8 ] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][6];
- h->mb.cache.intra4x4_pred_mode[x264_scan8[10] - 1] = h->mb.intra4x4_pred_mode[i_left_xy][3];
-
- /* load non_zero_count */
- h->mb.cache.non_zero_count[x264_scan8[0 ] - 1] = h->mb.non_zero_count[i_left_xy][5];
- h->mb.cache.non_zero_count[x264_scan8[2 ] - 1] = h->mb.non_zero_count[i_left_xy][7];
- h->mb.cache.non_zero_count[x264_scan8[8 ] - 1] = h->mb.non_zero_count[i_left_xy][13];
- h->mb.cache.non_zero_count[x264_scan8[10] - 1] = h->mb.non_zero_count[i_left_xy][15];
-
- h->mb.cache.non_zero_count[x264_scan8[16+0] - 1] = h->mb.non_zero_count[i_left_xy][16+1];
- h->mb.cache.non_zero_count[x264_scan8[16+2] - 1] = h->mb.non_zero_count[i_left_xy][16+3];
-
- h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 1] = h->mb.non_zero_count[i_left_xy][16+4+1];
- h->mb.cache.non_zero_count[x264_scan8[16+4+2] - 1] = h->mb.non_zero_count[i_left_xy][16+4+3];
- }
- else
- {
- h->mb.cache.intra4x4_pred_mode[x264_scan8[0 ] - 1] =
- h->mb.cache.intra4x4_pred_mode[x264_scan8[2 ] - 1] =
- h->mb.cache.intra4x4_pred_mode[x264_scan8[8 ] - 1] =
- h->mb.cache.intra4x4_pred_mode[x264_scan8[10] - 1] = -1;
-
- /* load non_zero_count */
- h->mb.cache.non_zero_count[x264_scan8[0 ] - 1] =
- h->mb.cache.non_zero_count[x264_scan8[2 ] - 1] =
- h->mb.cache.non_zero_count[x264_scan8[8 ] - 1] =
- h->mb.cache.non_zero_count[x264_scan8[10] - 1] =
- h->mb.cache.non_zero_count[x264_scan8[16+0] - 1] =
- h->mb.cache.non_zero_count[x264_scan8[16+2] - 1] =
- h->mb.cache.non_zero_count[x264_scan8[16+4+0] - 1] =
- h->mb.cache.non_zero_count[x264_scan8[16+4+2] - 1] = 0x80;
- }
-
- if( i_mb_y > 0 && i_mb_x < h->sps->i_mb_width - 1 )
- {
- h->mb.i_neighbour |= MB_TOPRIGHT;
- }
-
- /* load ref/mv/mvd */
- if( h->sh.i_type != SLICE_TYPE_I )
- {
- int s8x8 = 2 * h->mb.i_mb_stride;
- int s4x4 = 4 * h->mb.i_mb_stride;
-
- int i_top_left_xy = -1;
- int i_top_right_xy = -1;
-
- int i_list;
-
- if( h->mb.i_mb_y > 0 && h->mb.i_mb_x > 0 )
- {
- i_top_left_xy = i_top_xy - 1;
- }
- if( h->mb.i_mb_y > 0 && h->mb.i_mb_x < h->sps->i_mb_width - 1 )
- {
- i_top_right_xy = i_top_xy + 1;
- }
-
- for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_P ? 1 : 2 ); i_list++ )
- {
- /*
- h->mb.cache.ref[i_list][x264_scan8[5 ]+1] =
- h->mb.cache.ref[i_list][x264_scan8[7 ]+1] =
- h->mb.cache.ref[i_list][x264_scan8[13]+1] = -2;
- */
-
- if( i_top_left_xy >= 0 )
- {
- const int i8 = x264_scan8[0] - 1 - 1*8;
- const int ir = i_mb_8x8 - s8x8 - 1;
- const int iv = i_mb_4x4 - s4x4 - 1;
- h->mb.cache.ref[i_list][i8] = h->mb.ref[i_list][ir];
- h->mb.cache.mv[i_list][i8][0] = h->mb.mv[i_list][iv][0];
- h->mb.cache.mv[i_list][i8][1] = h->mb.mv[i_list][iv][1];
- }
- else
- {
- const int i8 = x264_scan8[0] - 1 - 1*8;
- h->mb.cache.ref[i_list][i8] = -2;
- h->mb.cache.mv[i_list][i8][0] = 0;
- h->mb.cache.mv[i_list][i8][1] = 0;
- }
-
- if( i_top_xy >= 0 )
- {
- const int i8 = x264_scan8[0] - 8;
- const int ir = i_mb_8x8 - s8x8;
- const int iv = i_mb_4x4 - s4x4;
-
- h->mb.cache.ref[i_list][i8+0] =
- h->mb.cache.ref[i_list][i8+1] = h->mb.ref[i_list][ir + 0];
- h->mb.cache.ref[i_list][i8+2] =
- h->mb.cache.ref[i_list][i8+3] = h->mb.ref[i_list][ir + 1];
-
- for( i = 0; i < 4; i++ )
- {
- h->mb.cache.mv[i_list][i8+i][0] = h->mb.mv[i_list][iv + i][0];
- h->mb.cache.mv[i_list][i8+i][1] = h->mb.mv[i_list][iv + i][1];
- }
- }
- else
- {
- const int i8 = x264_scan8[0] - 8;
- for( i = 0; i < 4; i++ )
- {
- h->mb.cache.ref[i_list][i8+i] = -2;
- h->mb.cache.mv[i_list][i8+i][0] =
- h->mb.cache.mv[i_list][i8+i][1] = 0;
- }
- }
-
- if( i_top_right_xy >= 0 )
- {
- const int i8 = x264_scan8[0] + 4 - 1*8;
- const int ir = i_mb_8x8 - s8x8 + 2;
- const int iv = i_mb_4x4 - s4x4 + 4;
-
- h->mb.cache.ref[i_list][i8] = h->mb.ref[i_list][ir];
- h->mb.cache.mv[i_list][i8][0] = h->mb.mv[i_list][iv][0];
- h->mb.cache.mv[i_list][i8][1] = h->mb.mv[i_list][iv][1];
- }
- else
- {
- const int i8 = x264_scan8[0] + 4 - 1*8;
- h->mb.cache.ref[i_list][i8] = -2;
- h->mb.cache.mv[i_list][i8][0] = 0;
- h->mb.cache.mv[i_list][i8][1] = 0;
- }
-
- if( i_left_xy >= 0 )
- {
- const int i8 = x264_scan8[0] - 1;
- const int ir = i_mb_8x8 - 1;
- const int iv = i_mb_4x4 - 1;
-
- h->mb.cache.ref[i_list][i8+0*8] =
- h->mb.cache.ref[i_list][i8+1*8] = h->mb.ref[i_list][ir + 0*s8x8];
- h->mb.cache.ref[i_list][i8+2*8] =
- h->mb.cache.ref[i_list][i8+3*8] = h->mb.ref[i_list][ir + 1*s8x8];
-
- for( i = 0; i < 4; i++ )
- {
- h->mb.cache.mv[i_list][i8+i*8][0] = h->mb.mv[i_list][iv + i*s4x4][0];
- h->mb.cache.mv[i_list][i8+i*8][1] = h->mb.mv[i_list][iv + i*s4x4][1];
- }
- }
- else
- {
- const int i8 = x264_scan8[0] - 1;
- for( i = 0; i < 4; i++ )
- {
- h->mb.cache.ref[i_list][i8+i*8] = -2;
- h->mb.cache.mv[i_list][i8+i*8][0] =
- h->mb.cache.mv[i_list][i8+i*8][1] = 0;
- }
- }
-
- if( h->param.b_cabac )
- {
- if( i_top_xy >= 0 )
- {
- const int i8 = x264_scan8[0] - 8;
- const int iv = i_mb_4x4 - s4x4;
- for( i = 0; i < 4; i++ )
- {
- h->mb.cache.mvd[i_list][i8+i][0] = h->mb.mvd[i_list][iv + i][0];
- h->mb.cache.mvd[i_list][i8+i][1] = h->mb.mvd[i_list][iv + i][1];
- }
- }
- else
- {
- const int i8 = x264_scan8[0] - 8;
- for( i = 0; i < 4; i++ )
- {
- h->mb.cache.mvd[i_list][i8+i][0] =
- h->mb.cache.mvd[i_list][i8+i][1] = 0;
- }
- }
-
- if( i_left_xy >= 0 )
- {
- const int i8 = x264_scan8[0] - 1;
- const int iv = i_mb_4x4 - 1;
- for( i = 0; i < 4; i++ )
- {
- h->mb.cache.mvd[i_list][i8+i*8][0] = h->mb.mvd[i_list][iv + i*s4x4][0];
- h->mb.cache.mvd[i_list][i8+i*8][1] = h->mb.mvd[i_list][iv + i*s4x4][1];
- }
- }
- else
- {
- const int i8 = x264_scan8[0] - 1;
- for( i = 0; i < 4; i++ )
- {
- h->mb.cache.mvd[i_list][i8+i*8][0] =
- h->mb.cache.mvd[i_list][i8+i*8][1] = 0;
- }
- }
- }
- }
- }
-}
-
-void x264_macroblock_cache_save( x264_t *h )
-{
- const int i_mb_xy = h->mb.i_mb_xy;
- const int i_mb_type = h->mb.i_type;
- const int i_mb_4x4 = 16 * h->mb.i_mb_stride * h->mb.i_mb_y + 4 * h->mb.i_mb_x;
- const int i_mb_8x8 = 4 * h->mb.i_mb_stride * h->mb.i_mb_y + 2 * h->mb.i_mb_x;
-
- int i;
-
- if( IS_SKIP( h->mb.i_type ) )
- h->mb.qp[i_mb_xy] = h->mb.i_last_qp;
-
- h->mb.i_last_dqp = h->mb.qp[i_mb_xy] - h->mb.i_last_qp;
- h->mb.i_last_qp = h->mb.qp[i_mb_xy];
-
- /* save intra4x4 */
- if( i_mb_type == I_4x4 )
- {
- h->mb.intra4x4_pred_mode[i_mb_xy][0] = h->mb.cache.intra4x4_pred_mode[x264_scan8[10] ];
- h->mb.intra4x4_pred_mode[i_mb_xy][1] = h->mb.cache.intra4x4_pred_mode[x264_scan8[11] ];
- h->mb.intra4x4_pred_mode[i_mb_xy][2] = h->mb.cache.intra4x4_pred_mode[x264_scan8[14] ];
- h->mb.intra4x4_pred_mode[i_mb_xy][3] = h->mb.cache.intra4x4_pred_mode[x264_scan8[15] ];
- h->mb.intra4x4_pred_mode[i_mb_xy][4] = h->mb.cache.intra4x4_pred_mode[x264_scan8[5] ];
- h->mb.intra4x4_pred_mode[i_mb_xy][5] = h->mb.cache.intra4x4_pred_mode[x264_scan8[7] ];
- h->mb.intra4x4_pred_mode[i_mb_xy][6] = h->mb.cache.intra4x4_pred_mode[x264_scan8[13] ];
- }
- else
- {
- h->mb.intra4x4_pred_mode[i_mb_xy][0] =
- h->mb.intra4x4_pred_mode[i_mb_xy][1] =
- h->mb.intra4x4_pred_mode[i_mb_xy][2] =
- h->mb.intra4x4_pred_mode[i_mb_xy][3] =
- h->mb.intra4x4_pred_mode[i_mb_xy][4] =
- h->mb.intra4x4_pred_mode[i_mb_xy][5] =
- h->mb.intra4x4_pred_mode[i_mb_xy][6] = I_PRED_4x4_DC;
- }
-
- if( i_mb_type == I_PCM )
- {
- h->mb.cbp[i_mb_xy] = 0x72f; /* all set */
- for( i = 0; i < 16 + 2*4; i++ )
- {
- h->mb.non_zero_count[i_mb_xy][i] = 16;
- }
- }
- else
- {
- /* save non zero count */
- for( i = 0; i < 16 + 2*4; i++ )
- {
- h->mb.non_zero_count[i_mb_xy][i] = h->mb.cache.non_zero_count[x264_scan8[i]];
- }
- }
-
- if( !IS_INTRA( i_mb_type ) )
- {
- int i_list;
- for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_P ? 1 : 2 ); i_list++ )
- {
- const int s8x8 = 2 * h->mb.i_mb_stride;
- const int s4x4 = 4 * h->mb.i_mb_stride;
- int y,x;
-
- h->mb.ref[i_list][i_mb_8x8+0+0*s8x8] = h->mb.cache.ref[i_list][x264_scan8[0]];
- h->mb.ref[i_list][i_mb_8x8+1+0*s8x8] = h->mb.cache.ref[i_list][x264_scan8[4]];
- h->mb.ref[i_list][i_mb_8x8+0+1*s8x8] = h->mb.cache.ref[i_list][x264_scan8[8]];
- h->mb.ref[i_list][i_mb_8x8+1+1*s8x8] = h->mb.cache.ref[i_list][x264_scan8[12]];
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][0] = h->mb.cache.mv[i_list][x264_scan8[0]+x+8*y][0];
- h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][1] = h->mb.cache.mv[i_list][x264_scan8[0]+x+8*y][1];
- }
- }
- }
- }
- else
- {
- int i_list;
- for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_P ? 1 : 2 ); i_list++ )
- {
- const int s8x8 = 2 * h->mb.i_mb_stride;
- const int s4x4 = 4 * h->mb.i_mb_stride;
- int y,x;
-
- h->mb.ref[i_list][i_mb_8x8+0+0*s8x8] =
- h->mb.ref[i_list][i_mb_8x8+1+0*s8x8] =
- h->mb.ref[i_list][i_mb_8x8+0+1*s8x8] =
- h->mb.ref[i_list][i_mb_8x8+1+1*s8x8] = -1;
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][0] = 0;
- h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][1] = 0;
- }
- }
- }
- }
-
- if( h->param.b_cabac )
- {
- if( i_mb_type == I_4x4 || i_mb_type == I_16x16 )
- h->mb.chroma_pred_mode[i_mb_xy] = h->mb.i_chroma_pred_mode;
- else
- h->mb.chroma_pred_mode[i_mb_xy] = I_PRED_CHROMA_DC;
-
- if( !IS_INTRA( i_mb_type ) && !IS_SKIP( i_mb_type ) )
- {
- int i_list;
- for( i_list = 0; i_list < 2; i_list++ )
- {
- const int s4x4 = 4 * h->mb.i_mb_stride;
- int y,x;
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][0] = h->mb.cache.mvd[i_list][x264_scan8[0]+x+8*y][0];
- h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][1] = h->mb.cache.mvd[i_list][x264_scan8[0]+x+8*y][1];
- }
- }
- }
- }
- else
- {
- int i_list;
- for( i_list = 0; i_list < 2; i_list++ )
- {
- const int s4x4 = 4 * h->mb.i_mb_stride;
- int y,x;
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][0] = 0;
- h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][1] = 0;
- }
- }
- }
- }
- }
-}
-
+++ /dev/null
-/*****************************************************************************
- * macroblock.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: macroblock.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _MACROBLOCK_H
-#define _MACROBLOCK_H 1
-
-enum macroblock_position_e
-{
- MB_LEFT = 0x01,
- MB_TOP = 0x02,
- MB_TOPRIGHT = 0x04,
-
- MB_PRIVATE = 0x10,
-};
-
-
-/* XXX mb_type isn't the one written in the bitstream -> only internal usage */
-#define IS_INTRA(type) ( (type) == I_4x4 || (type) == I_16x16 )
-#define IS_SKIP(type) ( (type) == P_SKIP || (type) == B_SKIP )
-enum mb_class_e
-{
- I_4x4 = 0,
- I_16x16 = 1,
- I_PCM = 2,
-
- P_L0 = 3,
- P_8x8 = 4,
- P_SKIP = 5,
-
- B_DIRECT = 6,
- B_L0_L0 = 7,
- B_L0_L1 = 8,
- B_L0_BI = 9,
- B_L1_L0 = 10,
- B_L1_L1 = 11,
- B_L1_BI = 12,
- B_BI_L0 = 13,
- B_BI_L1 = 14,
- B_BI_BI = 15,
- B_8x8 = 16,
- B_SKIP = 17,
-};
-static const int x264_mb_type_list0_table[18][2] =
-{
- {0,0}, {0,0}, {0,0}, /* INTRA */
- {1,1}, /* P_L0 */
- {0,0}, /* P_8x8 */
- {1,1}, /* P_SKIP */
- {0,0}, /* B_DIRECT */
- {1,1}, {1,0}, {1,1}, /* B_L0_* */
- {0,1}, {0,0}, {0,1}, /* B_L1_* */
- {1,1}, {1,0}, {1,1}, /* B_BI_* */
- {0,0}, /* B_8x8 */
- {0,0} /* B_SKIP */
-};
-static const int x264_mb_type_list1_table[18][2] =
-{
- {0,0}, {0,0}, {0,0}, /* INTRA */
- {0,0}, /* P_L0 */
- {0,0}, /* P_8x8 */
- {0,0}, /* P_SKIP */
- {0,0}, /* B_DIRECT */
- {0,0}, {0,1}, {0,1}, /* B_L0_* */
- {1,0}, {1,1}, {1,1}, /* B_L1_* */
- {1,0}, {1,1}, {1,1}, /* B_BI_* */
- {0,0}, /* B_8x8 */
- {0,0} /* B_SKIP */
-};
-
-#define IS_SUB4x4(type) ( (type ==D_L0_4x4)||(type ==D_L1_4x4)||(type ==D_BI_4x4))
-#define IS_SUB4x8(type) ( (type ==D_L0_4x8)||(type ==D_L1_4x8)||(type ==D_BI_4x8))
-#define IS_SUB8x4(type) ( (type ==D_L0_8x4)||(type ==D_L1_8x4)||(type ==D_BI_8x4))
-#define IS_SUB8x8(type) ( (type ==D_L0_8x8)||(type ==D_L1_8x8)||(type ==D_BI_8x8)||(type ==D_DIRECT_8x8))
-enum mb_partition_e
-{
- /* sub partition type for P_8x8 and B_8x8 */
- D_L0_4x4 = 0,
- D_L0_8x4 = 1,
- D_L0_4x8 = 2,
- D_L0_8x8 = 3,
-
- /* sub partition type for B_8x8 only */
- D_L1_4x4 = 4,
- D_L1_8x4 = 5,
- D_L1_4x8 = 6,
- D_L1_8x8 = 7,
-
- D_BI_4x4 = 8,
- D_BI_8x4 = 9,
- D_BI_4x8 = 10,
- D_BI_8x8 = 11,
- D_DIRECT_8x8 = 12,
-
- /* partition */
- D_8x8 = 13,
- D_16x8 = 14,
- D_8x16 = 15,
- D_16x16 = 16,
-};
-
-static const int x264_mb_partition_count_table[17] =
-{
- /* sub L0 */
- 4, 2, 2, 1,
- /* sub L1 */
- 4, 2, 2, 1,
- /* sub BI */
- 4, 2, 2, 1,
- /* Direct */
- 1,
- /* Partition */
- 4, 2, 2, 1
-};
-
-void x264_macroblock_cache_init( x264_t *h );
-void x264_macroblock_cache_load( x264_t *h, int, int );
-void x264_macroblock_cache_save( x264_t *h );
-void x264_macroblock_cache_end( x264_t *h );
-
-void x264_mb_dequant_4x4_dc( int16_t dct[4][4], int i_qscale );
-void x264_mb_dequant_2x2_dc( int16_t dct[2][2], int i_qscale );
-void x264_mb_dequant_4x4( int16_t dct[4][4], int i_qscale );
-
-/* x264_mb_predict_mv_16x16:
- * set mvp with predicted mv for D_16x16 block
- * h->mb. need only valid values from other blocks */
-void x264_mb_predict_mv_16x16( x264_t *h, int i_list, int i_ref, int mvp[2] );
-/* x264_mb_predict_mv_pskip:
- * set mvp with predicted mv for P_SKIP
- * h->mb. need only valid values from other blocks */
-void x264_mb_predict_mv_pskip( x264_t *h, int mv[2] );
-/* x264_mb_predict_mv:
- * set mvp with predicted mv for all blocks except P_SKIP
- * h->mb. need valid ref/partition/sub of current block to be valid
- * and valid mv/ref from other blocks . */
-void x264_mb_predict_mv( x264_t *h, int i_list, int idx, int i_width, int mvp[2] );
-/* x264_mb_predict_mv_ref16x16:
- * set mvc with D_16x16 prediction.
- * uses all neighbors, even those that didn't end up using this ref.
- * need only valid values from other blocks */
-void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int mvc[4][2], int *i_mvc );
-
-
-int x264_mb_predict_intra4x4_mode( x264_t *h, int idx );
-int x264_mb_predict_non_zero_code( x264_t *h, int idx );
-
-void x264_mb_encode_i4x4( x264_t *h, int idx, int i_qscale );
-
-void x264_mb_mc( x264_t *h );
-
-
-static inline void x264_macroblock_cache_ref( x264_t *h, int x, int y, int width, int height, int i_list, int ref )
-{
- int dy, dx;
- for( dy = 0; dy < height; dy++ )
- {
- for( dx = 0; dx < width; dx++ )
- {
- h->mb.cache.ref[i_list][X264_SCAN8_0+x+dx+8*(y+dy)] = ref;
- }
- }
-}
-static inline void x264_macroblock_cache_mv( x264_t *h, int x, int y, int width, int height, int i_list, int mvx, int mvy )
-{
- int dy, dx;
- for( dy = 0; dy < height; dy++ )
- {
- for( dx = 0; dx < width; dx++ )
- {
- h->mb.cache.mv[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][0] = mvx;
- h->mb.cache.mv[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][1] = mvy;
- }
- }
-}
-static inline void x264_macroblock_cache_mvd( x264_t *h, int x, int y, int width, int height, int i_list, int mdx, int mdy )
-{
- int dy, dx;
- for( dy = 0; dy < height; dy++ )
- {
- for( dx = 0; dx < width; dx++ )
- {
- h->mb.cache.mvd[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][0] = mdx;
- h->mb.cache.mvd[i_list][X264_SCAN8_0+x+dx+8*(y+dy)][1] = mdy;
- }
- }
-}
-
-#endif
-
+++ /dev/null
-/*****************************************************************************
- * mc.c: h264 encoder library (Motion Compensation)
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: mc.c,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "../x264.h"
-
-#include "mc.h"
-#include "clip1.h"
-
-#ifdef _MSC_VER
-#undef HAVE_MMXEXT /* not finished now */
-#endif
-#ifdef HAVE_MMXEXT
-# include "i386/mc.h"
-#endif
-#ifdef ARCH_PPC
-# include "ppc/mc.h"
-#endif
-
-
-static inline int x264_tapfilter( uint8_t *pix, int i_pix_next )
-{
- return pix[-2*i_pix_next] - 5*pix[-1*i_pix_next] + 20*(pix[0] + pix[1*i_pix_next]) - 5*pix[ 2*i_pix_next] + pix[ 3*i_pix_next];
-}
-static inline int x264_tapfilter1( uint8_t *pix )
-{
- return pix[-2] - 5*pix[-1] + 20*(pix[0] + pix[1]) - 5*pix[ 2] + pix[ 3];
-}
-
-static inline void pixel_avg( uint8_t *dst, int i_dst_stride,
- uint8_t *src1, int i_src1_stride,
- uint8_t *src2, int i_src2_stride,
- int i_width, int i_height )
-{
- int x, y;
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < i_width; x++ )
- {
- dst[x] = ( src1[x] + src2[x] + 1 ) >> 1;
- }
- dst += i_dst_stride;
- src1 += i_src1_stride;
- src2 += i_src2_stride;
- }
-}
-
-typedef void (*pf_mc_t)(uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height );
-
-static void mc_copy( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- int y;
-
- for( y = 0; y < i_height; y++ )
- {
- memcpy( dst, src, i_width );
-
- src += i_src_stride;
- dst += i_dst_stride;
- }
-}
-static inline void mc_hh( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- int x, y;
-
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < i_width; x++ )
- {
- dst[x] = x264_mc_clip1( ( x264_tapfilter1( &src[x] ) + 16 ) >> 5 );
- }
- src += i_src_stride;
- dst += i_dst_stride;
- }
-}
-static inline void mc_hv( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- int x, y;
-
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < i_width; x++ )
- {
- dst[x] = x264_mc_clip1( ( x264_tapfilter( &src[x], i_src_stride ) + 16 ) >> 5 );
- }
- src += i_src_stride;
- dst += i_dst_stride;
- }
-}
-static inline void mc_hc( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t *out;
- uint8_t *pix;
- int x, y;
-
- for( x = 0; x < i_width; x++ )
- {
- int tap[6];
-
- pix = &src[x];
- out = &dst[x];
-
- tap[0] = x264_tapfilter1( &pix[-2*i_src_stride] );
- tap[1] = x264_tapfilter1( &pix[-1*i_src_stride] );
- tap[2] = x264_tapfilter1( &pix[ 0*i_src_stride] );
- tap[3] = x264_tapfilter1( &pix[ 1*i_src_stride] );
- tap[4] = x264_tapfilter1( &pix[ 2*i_src_stride] );
-
- for( y = 0; y < i_height; y++ )
- {
- tap[5] = x264_tapfilter1( &pix[ 3*i_src_stride] );
-
- *out = x264_mc_clip1( ( tap[0] - 5*tap[1] + 20 * tap[2] + 20 * tap[3] -5*tap[4] + tap[5] + 512 ) >> 10 );
-
- /* Next line */
- pix += i_src_stride;
- out += i_dst_stride;
- tap[0] = tap[1];
- tap[1] = tap[2];
- tap[2] = tap[3];
- tap[3] = tap[4];
- tap[4] = tap[5];
- }
- }
-}
-
-/* mc I+H */
-static void mc_xy10( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hh( src, i_src_stride, tmp, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, src, i_src_stride, tmp, i_width, i_width, i_height );
-}
-static void mc_xy30( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hh( src, i_src_stride, tmp, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, src+1, i_src_stride, tmp, i_width, i_width, i_height );
-}
-/* mc I+V */
-static void mc_xy01( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hv( src, i_src_stride, tmp, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, src, i_src_stride, tmp, i_width, i_width, i_height );
-}
-static void mc_xy03( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hv( src, i_src_stride, tmp, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, src+i_src_stride, i_src_stride, tmp, i_width, i_width, i_height );
-}
-/* H+V */
-static void mc_xy11( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
-
- mc_hv( src, i_src_stride, tmp1, i_width, i_width, i_height );
- mc_hh( src, i_src_stride, tmp2, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
-}
-static void mc_xy31( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
-
- mc_hv( src+1, i_src_stride, tmp1, i_width, i_width, i_height );
- mc_hh( src, i_src_stride, tmp2, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
-}
-static void mc_xy13( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
-
- mc_hv( src, i_src_stride, tmp1, i_width, i_width, i_height );
- mc_hh( src+i_src_stride, i_src_stride, tmp2, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
-}
-static void mc_xy33( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
-
- mc_hv( src+1, i_src_stride, tmp1, i_width, i_width, i_height );
- mc_hh( src+i_src_stride, i_src_stride, tmp2, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
-}
-static void mc_xy21( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
-
- mc_hc( src, i_src_stride, tmp1, i_width, i_width, i_height );
- mc_hh( src, i_src_stride, tmp2, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
-}
-static void mc_xy12( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
-
- mc_hc( src, i_src_stride, tmp1, i_width, i_width, i_height );
- mc_hv( src, i_src_stride, tmp2, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
-}
-static void mc_xy32( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
-
- mc_hc( src, i_src_stride, tmp1, i_width, i_width, i_height );
- mc_hv( src+1, i_src_stride, tmp2, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
-}
-static void mc_xy23( uint8_t *src, int i_src_stride, uint8_t *dst, int i_dst_stride, int i_width, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
-
- mc_hc( src, i_src_stride, tmp1, i_width, i_width, i_height );
- mc_hh( src+i_src_stride, i_src_stride, tmp2, i_width, i_width, i_height );
- pixel_avg( dst, i_dst_stride, tmp1, i_width, tmp2, i_width, i_width, i_height );
-}
-
-static void motion_compensation_luma( uint8_t *src, int i_src_stride,
- uint8_t *dst, int i_dst_stride,
- int mvx,int mvy,
- int i_width, int i_height )
-{
- static pf_mc_t pf_mc[4][4] = /*XXX [dqy][dqx] */
- {
- { mc_copy, mc_xy10, mc_hh, mc_xy30 },
- { mc_xy01, mc_xy11, mc_xy21, mc_xy31 },
- { mc_hv, mc_xy12, mc_hc, mc_xy32 },
- { mc_xy03, mc_xy13, mc_xy23, mc_xy33 },
- };
-
- src += (mvy >> 2) * i_src_stride + (mvx >> 2);
- pf_mc[mvy&0x03][mvx&0x03]( src, i_src_stride, dst, i_dst_stride, i_width, i_height );
-}
-
-/* full chroma mc (ie until 1/8 pixel)*/
-static void motion_compensation_chroma( uint8_t *src, int i_src_stride,
- uint8_t *dst, int i_dst_stride,
- int mvx, int mvy,
- int i_width, int i_height )
-{
- uint8_t *srcp;
- int x, y;
-
- const int d8x = mvx&0x07;
- const int d8y = mvy&0x07;
-
- const int cA = (8-d8x)*(8-d8y);
- const int cB = d8x *(8-d8y);
- const int cC = (8-d8x)*d8y;
- const int cD = d8x *d8y;
-
- src += (mvy >> 3) * i_src_stride + (mvx >> 3);
- srcp = &src[i_src_stride];
-
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < i_width; x++ )
- {
- dst[x] = ( cA*src[x] + cB*src[x+1] +
- cC*srcp[x] + cD*srcp[x+1] + 32 ) >> 6;
- }
- dst += i_dst_stride;
-
- src = srcp;
- srcp += i_src_stride;
- }
-}
-
-void x264_mc_init( int cpu, x264_mc_function_t pf[2] )
-{
- pf[MC_LUMA] = motion_compensation_luma;
- pf[MC_CHROMA] = motion_compensation_chroma;
-
-#ifdef HAVE_MMXEXT
- if( cpu&X264_CPU_MMXEXT )
- x264_mc_mmxext_init( pf );
-#endif
-#ifdef HAVE_SSE2
- if( cpu&X264_CPU_SSE2 )
- x264_mc_sse2_init( pf );
-#endif
-
-#ifdef ARCH_PPC
- if( cpu&X264_CPU_ALTIVEC )
- x264_mc_altivec_init( pf );
-#endif
-}
-
+++ /dev/null
-/*****************************************************************************
- * mc.h: h264 encoder library (Motion Compensation)
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: mc.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _MC_H
-#define _MC_H 1
-
-/* Do the MC
- * XXX: Only width = 4, 8 or 16 are valid
- * width == 4 -> height == 4 or 8
- * width == 8 -> height == 4 or 8 or 16
- * width == 16-> height == 8 or 16
- * */
-
-typedef void (*x264_mc_function_t)(uint8_t *, int, uint8_t *, int,
- int mvx, int mvy,
- int i_width, int i_height );
-enum
-{
- MC_LUMA = 0,
- MC_CHROMA = 1,
-};
-
-void x264_mc_init( int cpu, x264_mc_function_t pf[2] );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * mdate.c: h264 encoder
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: mdate.c,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-
-#if !(defined(_MSC_VER) || defined(__MINGW32__))
-#include <sys/time.h>
-#else
-#include <sys/types.h>
-#include <sys/timeb.h>
-#endif
-#include <time.h>
-
-int64_t x264_mdate( void )
-{
-#if !(defined(_MSC_VER) || defined(__MINGW32__))
- struct timeval tv_date;
-
- gettimeofday( &tv_date, NULL );
- return( (int64_t) tv_date.tv_sec * 1000000 + (int64_t) tv_date.tv_usec );
-#else
- struct _timeb tb;
- _ftime(&tb);
- return ((int64_t)tb.time * (1000) + (int64_t)tb.millitm) * (1000);
-#endif
-}
-
+++ /dev/null
-/*****************************************************************************
- * pixel.c: h264 encoder
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: pixel.c,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "../x264.h"
-#include "pixel.h"
-
-#ifdef HAVE_MMXEXT
-# include "i386/pixel.h"
-#endif
-#ifdef ARCH_PPC
-# include "ppc/pixel.h"
-#endif
-
-
-/****************************************************************************
- * pixel_sad_WxH
- ****************************************************************************/
-#define PIXEL_SAD_C( name, lx, ly ) \
-static int name( uint8_t *pix1, int i_stride_pix1, \
- uint8_t *pix2, int i_stride_pix2 ) \
-{ \
- int i_sum = 0; \
- int x, y; \
- for( y = 0; y < ly; y++ ) \
- { \
- for( x = 0; x < lx; x++ ) \
- { \
- i_sum += abs( pix1[x] - pix2[x] ); \
- } \
- pix1 += i_stride_pix1; \
- pix2 += i_stride_pix2; \
- } \
- return i_sum; \
-}
-
-
-PIXEL_SAD_C( pixel_sad_16x16, 16, 16 )
-PIXEL_SAD_C( pixel_sad_16x8, 16, 8 )
-PIXEL_SAD_C( pixel_sad_8x16, 8, 16 )
-PIXEL_SAD_C( pixel_sad_8x8, 8, 8 )
-PIXEL_SAD_C( pixel_sad_8x4, 8, 4 )
-PIXEL_SAD_C( pixel_sad_4x8, 4, 8 )
-PIXEL_SAD_C( pixel_sad_4x4, 4, 4 )
-
-static void pixel_sub_4x4( int16_t diff[4][4], uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
-{
- int y, x;
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- diff[y][x] = pix1[x] - pix2[x];
- }
- pix1 += i_pix1;
- pix2 += i_pix2;
- }
-}
-
-static int pixel_satd_wxh( uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2, int i_width, int i_height )
-{
- int16_t tmp[4][4];
- int16_t diff[4][4];
- int x, y;
- int i_satd = 0;
-
- for( y = 0; y < i_height; y += 4 )
- {
- for( x = 0; x < i_width; x += 4 )
- {
- int d;
-
- pixel_sub_4x4( diff, &pix1[x], i_pix1, &pix2[x], i_pix2 );
-
- for( d = 0; d < 4; d++ )
- {
- int s01, s23;
- int d01, d23;
-
- s01 = diff[d][0] + diff[d][1]; s23 = diff[d][2] + diff[d][3];
- d01 = diff[d][0] - diff[d][1]; d23 = diff[d][2] - diff[d][3];
-
- tmp[d][0] = s01 + s23;
- tmp[d][1] = s01 - s23;
- tmp[d][2] = d01 - d23;
- tmp[d][3] = d01 + d23;
- }
- for( d = 0; d < 4; d++ )
- {
- int s01, s23;
- int d01, d23;
-
- s01 = tmp[0][d] + tmp[1][d]; s23 = tmp[2][d] + tmp[3][d];
- d01 = tmp[0][d] - tmp[1][d]; d23 = tmp[2][d] - tmp[3][d];
-
- i_satd += abs( s01 + s23 ) + abs( s01 - s23 ) + abs( d01 - d23 ) + abs( d01 + d23 );
- }
-
- }
- pix1 += 4 * i_pix1;
- pix2 += 4 * i_pix2;
- }
-
- return i_satd / 2;
-}
-#define PIXEL_SATD_C( name, width, height ) \
-static int name( uint8_t *pix1, int i_stride_pix1, \
- uint8_t *pix2, int i_stride_pix2 ) \
-{ \
- return pixel_satd_wxh( pix1, i_stride_pix1, pix2, i_stride_pix2, width, height ); \
-}
-PIXEL_SATD_C( pixel_satd_16x16, 16, 16 )
-PIXEL_SATD_C( pixel_satd_16x8, 16, 8 )
-PIXEL_SATD_C( pixel_satd_8x16, 8, 16 )
-PIXEL_SATD_C( pixel_satd_8x8, 8, 8 )
-PIXEL_SATD_C( pixel_satd_8x4, 8, 4 )
-PIXEL_SATD_C( pixel_satd_4x8, 4, 8 )
-PIXEL_SATD_C( pixel_satd_4x4, 4, 4 )
-
-
-static inline void pixel_avg_wxh( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int width, int height )
-{
- int x, y;
- for( y = 0; y < height; y++ )
- {
- for( x = 0; x < width; x++ )
- {
- dst[x] = ( dst[x] + src[x] + 1 ) >> 1;
- }
- dst += i_dst;
- src += i_src;
- }
-}
-
-
-#define PIXEL_AVG_C( name, width, height ) \
-static void name( uint8_t *pix1, int i_stride_pix1, \
- uint8_t *pix2, int i_stride_pix2 ) \
-{ \
- pixel_avg_wxh( pix1, i_stride_pix1, pix2, i_stride_pix2, width, height ); \
-}
-PIXEL_AVG_C( pixel_avg_16x16, 16, 16 )
-PIXEL_AVG_C( pixel_avg_16x8, 16, 8 )
-PIXEL_AVG_C( pixel_avg_8x16, 8, 16 )
-PIXEL_AVG_C( pixel_avg_8x8, 8, 8 )
-PIXEL_AVG_C( pixel_avg_8x4, 8, 4 )
-PIXEL_AVG_C( pixel_avg_4x8, 4, 8 )
-PIXEL_AVG_C( pixel_avg_4x4, 4, 4 )
-
-/****************************************************************************
- * x264_pixel_init:
- ****************************************************************************/
-void x264_pixel_init( int cpu, x264_pixel_function_t *pixf )
-{
- pixf->sad[PIXEL_16x16] = pixel_sad_16x16;
- pixf->sad[PIXEL_16x8] = pixel_sad_16x8;
- pixf->sad[PIXEL_8x16] = pixel_sad_8x16;
- pixf->sad[PIXEL_8x8] = pixel_sad_8x8;
- pixf->sad[PIXEL_8x4] = pixel_sad_8x4;
- pixf->sad[PIXEL_4x8] = pixel_sad_4x8;
- pixf->sad[PIXEL_4x4] = pixel_sad_4x4;
-
- pixf->satd[PIXEL_16x16]= pixel_satd_16x16;
- pixf->satd[PIXEL_16x8] = pixel_satd_16x8;
- pixf->satd[PIXEL_8x16] = pixel_satd_8x16;
- pixf->satd[PIXEL_8x8] = pixel_satd_8x8;
- pixf->satd[PIXEL_8x4] = pixel_satd_8x4;
- pixf->satd[PIXEL_4x8] = pixel_satd_4x8;
- pixf->satd[PIXEL_4x4] = pixel_satd_4x4;
-
- pixf->avg[PIXEL_16x16]= pixel_avg_16x16;
- pixf->avg[PIXEL_16x8] = pixel_avg_16x8;
- pixf->avg[PIXEL_8x16] = pixel_avg_8x16;
- pixf->avg[PIXEL_8x8] = pixel_avg_8x8;
- pixf->avg[PIXEL_8x4] = pixel_avg_8x4;
- pixf->avg[PIXEL_4x8] = pixel_avg_4x8;
- pixf->avg[PIXEL_4x4] = pixel_avg_4x4;
-#ifdef HAVE_MMXEXT
- if( cpu&X264_CPU_MMXEXT )
- {
- pixf->sad[PIXEL_16x16] = x264_pixel_sad_16x16_mmxext;
- pixf->sad[PIXEL_16x8 ] = x264_pixel_sad_16x8_mmxext;
- pixf->sad[PIXEL_8x16 ] = x264_pixel_sad_8x16_mmxext;
- pixf->sad[PIXEL_8x8 ] = x264_pixel_sad_8x8_mmxext;
- pixf->sad[PIXEL_8x4 ] = x264_pixel_sad_8x4_mmxext;
- pixf->sad[PIXEL_4x8 ] = x264_pixel_sad_4x8_mmxext;
- pixf->sad[PIXEL_4x4] = x264_pixel_sad_4x4_mmxext;
-
- pixf->satd[PIXEL_16x16]= x264_pixel_satd_16x16_mmxext;
- pixf->satd[PIXEL_16x8] = x264_pixel_satd_16x8_mmxext;
- pixf->satd[PIXEL_8x16] = x264_pixel_satd_8x16_mmxext;
- pixf->satd[PIXEL_8x8] = x264_pixel_satd_8x8_mmxext;
- pixf->satd[PIXEL_8x4] = x264_pixel_satd_8x4_mmxext;
- pixf->satd[PIXEL_4x8] = x264_pixel_satd_4x8_mmxext;
- pixf->satd[PIXEL_4x4] = x264_pixel_satd_4x4_mmxext;
- }
-#endif
-#ifdef ARCH_PPC
- if( cpu&X264_CPU_ALTIVEC )
- {
- x264_pixel_altivec_init( pixf );
- }
-#endif
-}
-
+++ /dev/null
-/*****************************************************************************
- * pixel.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: pixel.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _PIXEL_H
-#define _PIXEL_H 1
-
-typedef int (*x264_pixel_sad_t) ( uint8_t *, int, uint8_t *, int );
-typedef int (*x264_pixel_satd_t)( uint8_t *, int, uint8_t *, int );
-typedef void (*x264_pixel_avg_t) ( uint8_t *, int, uint8_t *, int );
-
-enum
-{
- PIXEL_16x16 = 0,
- PIXEL_16x8 = 1,
- PIXEL_8x16 = 2,
- PIXEL_8x8 = 3,
- PIXEL_8x4 = 4,
- PIXEL_4x8 = 5,
- PIXEL_4x4 = 6,
-};
-
-static const struct {
- int w;
- int h;
-} x264_pixel_size[7] = {
- { 16, 16 },
- { 16, 8 }, { 8, 16 },
- { 8, 8 },
- { 8, 4 }, { 4, 8 },
- { 4, 4 }
-};
-
-typedef struct
-{
- x264_pixel_sad_t sad[7];
- x264_pixel_satd_t satd[7];
- x264_pixel_avg_t avg[7];
-} x264_pixel_function_t;
-
-void x264_pixel_init( int cpu, x264_pixel_function_t *pixf );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * mc.c: h264 encoder library (Motion Compensation)
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: mc.c,v 1.1 2004/06/03 19:27:07 fenrir Exp $
- *
- * Authors: Eric Petit <titer@m0k.org>
- *
- * 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 <stdarg.h>
-
-#ifdef SYS_LINUX
-#include <altivec.h>
-#endif
-
-#include "x264.h"
-#include "../mc.h"
-#include "../clip1.h"
-#include "mc.h"
-#include "ppccommon.h"
-
-typedef void (*pf_mc_t)( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height );
-
-static inline int x264_tapfilter( uint8_t *pix, int i_pix_next )
-{
- return pix[-2*i_pix_next] - 5*pix[-1*i_pix_next] + 20*(pix[0] +
- pix[1*i_pix_next]) - 5*pix[ 2*i_pix_next] +
- pix[ 3*i_pix_next];
-}
-static inline int x264_tapfilter1( uint8_t *pix )
-{
- return pix[-2] - 5*pix[-1] + 20*(pix[0] + pix[1]) - 5*pix[ 2] +
- pix[ 3];
-}
-
-/* pixel_avg */
-static inline void pixel_avg_w4( uint8_t *dst, int i_dst,
- uint8_t *src1, int i_src1,
- uint8_t *src2, int i_src2,
- int i_height )
-{
- int x, y;
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- dst[x] = ( src1[x] + src2[x] + 1 ) >> 1;
- }
- dst += i_dst;
- src1 += i_src1;
- src2 += i_src2;
- }
-}
-static inline void pixel_avg_w8( uint8_t *dst, int i_dst,
- uint8_t *src1, int i_src1,
- uint8_t *src2, int i_src2,
- int i_height )
-{
- /* TODO - optimize */
- pixel_avg_w4( &dst[0], i_dst, &src1[0], i_src1, &src2[0], i_src2,
- i_height );
- pixel_avg_w4( &dst[4], i_dst, &src1[4], i_src1, &src2[4], i_src2,
- i_height );
-}
-static inline void pixel_avg_w16( uint8_t *dst, int i_dst,
- uint8_t *src1, int i_src1,
- uint8_t *src2, int i_src2,
- int i_height )
-{
- int y;
- vector_u8_t src1v, src2v;
- for( y = 0; y < i_height; y++ )
- {
- LOAD_16( src1, src1v );
- LOAD_16( src2, src2v );
- src1v = vec_avg( src1v, src2v );
- STORE_16( src1v, dst );
-
- dst += i_dst;
- src1 += i_src1;
- src2 += i_src2;
- }
-}
-
-/* mc_copy: plain c */
-#define MC_COPY( name, a ) \
-static void name( uint8_t *src, int i_src, \
- uint8_t *dst, int i_dst, int i_height ) \
-{ \
- int y; \
- for( y = 0; y < i_height; y++ ) \
- { \
- memcpy( dst, src, a ); \
- src += i_src; \
- dst += i_dst; \
- } \
-}
-MC_COPY( mc_copy_w4, 4 )
-MC_COPY( mc_copy_w8, 8 )
-MC_COPY( mc_copy_w16, 16 )
-
-/* TAP_FILTER:
- a is source (vector_s16_t [6])
- b is a temporary vector_s16_t
- c is the result
-
- c = src[0] + a[5] - 5 * ( a[1] + a[4] ) + 20 * ( a[2] + a[3] );
- c += 16;
- c >>= 5;
- c += 80; */
-#define TAP_FILTER( a, b, c ) \
- c = vec_add( a[0], a[5] ); \
- b = vec_add( a[1], a[4] ); \
- c = vec_sub( c, b ); \
- b = vec_sl( b, vec_splat_u16( 2 ) ); \
- c = vec_sub( c, b ); \
- b = vec_add( a[2], a[3] ); \
- b = vec_sl( b, vec_splat_u16( 2 ) ); \
- c = vec_add( c, b ); \
- b = vec_sl( b, vec_splat_u16( 2 ) ); \
- c = vec_add( c, b ); \
- c = vec_add( c, vec_splat_s16( 8 ) ); \
- c = vec_add( c, vec_splat_s16( 8 ) ); \
- c = vec_sr( c, vec_splat_u16( 5 ) ); \
- c = vec_add( c, vec_sl( vec_splat_s16( 5 ), \
- vec_splat_u16( 4 ) ) );
-
-/* mc_hh */
-static inline void mc_hh_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- int x, y;
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- dst[x] = x264_mc_clip1( ( x264_tapfilter1( &src[x] ) +
- 16 ) >> 5 );
- }
- src += i_src;
- dst += i_dst;
- }
-}
-static inline void mc_hh_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- long x, y;
- DECLARE_ALIGNED( int16_t, tmp[8], 16 );
-
- LOAD_ZERO;
- vector_u8_t loadv;
- vector_s16_t srcv[6];
- vector_u8_t * _srcv = (vector_u8_t*) srcv;
- vector_s16_t dstv;
- vector_s16_t tmpv;
-
- for( y = 0; y < i_height; y++ )
- {
- LOAD_16( &src[-2], loadv );
-
- for( x = 0; x < 6; x++ )
- {
- _srcv[x] = vec_perm( loadv, zero_u8,
- vec_lvsl( 0, (int*) x ) );
- CONVERT_U8_TO_S16( srcv[x] );
- }
-
- TAP_FILTER( srcv, tmpv, dstv );
- vec_st( dstv, 0, tmp );
-
- for( x = 0; x < 8; x++ )
- {
- dst[x] = x264_mc_clip1_table[tmp[x]];
- }
-
- src += i_src;
- dst += i_dst;
- }
-}
-static inline void mc_hh_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- mc_hh_w8( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hh_w8( &src[8], i_src, &dst[8], i_dst, i_height );
-}
-
-/* mc_hv */
-static inline void mc_hv_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- int x, y;
- for( y = 0; y < i_height; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- dst[x] = x264_mc_clip1( ( x264_tapfilter( &src[x], i_src ) +
- 16 ) >> 5 );
- }
- src += i_src;
- dst += i_dst;
- }
-}
-static inline void mc_hv_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- int x, y;
- DECLARE_ALIGNED( int16_t, tmp[8], 16 );
-
- LOAD_ZERO;
- vector_s16_t srcv[6];
- vector_u8_t * _srcv = (vector_u8_t*) srcv;
- vector_s16_t dstv;
- vector_s16_t tmpv;
-
- for( y = 0; y < i_height; y++ )
- {
- if( y )
- {
- for( x = 0; x < 5; x++ )
- {
- srcv[x] = srcv[x+1];
- }
- LOAD_8( &src[3*i_src], _srcv[5] );
- CONVERT_U8_TO_S16( srcv[5] );
- }
- else
- {
- for( x = 0; x < 6; x++ )
- {
- LOAD_8( &src[(x-2)*i_src], _srcv[x] );
- CONVERT_U8_TO_S16( srcv[x] );
- }
- }
-
- TAP_FILTER( srcv, tmpv, dstv );
- vec_st( dstv, 0, tmp );
-
- for( x = 0; x < 8; x++ )
- {
- dst[x] = x264_mc_clip1_table[tmp[x]];
- }
- src += i_src;
- dst += i_dst;
- }
-}
-static inline void mc_hv_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- mc_hv_w8( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hv_w8( &src[8], i_src, &dst[8], i_dst, i_height );
-}
-
-/* mc_hc */
-static inline void mc_hc_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t *out;
- uint8_t *pix;
- int x, y;
-
- for( x = 0; x < 4; x++ )
- {
- int tap[6];
-
- pix = &src[x];
- out = &dst[x];
-
- tap[0] = x264_tapfilter1( &pix[-2*i_src] );
- tap[1] = x264_tapfilter1( &pix[-1*i_src] );
- tap[2] = x264_tapfilter1( &pix[ 0*i_src] );
- tap[3] = x264_tapfilter1( &pix[ 1*i_src] );
- tap[4] = x264_tapfilter1( &pix[ 2*i_src] );
-
- for( y = 0; y < i_height; y++ )
- {
- tap[5] = x264_tapfilter1( &pix[ 3*i_src] );
-
- *out = x264_mc_clip1( ( tap[0] - 5*tap[1] + 20 * tap[2] +
- 20 * tap[3] -5*tap[4] + tap[5] +
- 512 ) >> 10 );
-
- /* Next line */
- pix += i_src;
- out += i_dst;
- tap[0] = tap[1];
- tap[1] = tap[2];
- tap[2] = tap[3];
- tap[3] = tap[4];
- tap[4] = tap[5];
- }
- }
-}
-static inline void mc_hc_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- /* TODO: optimize */
- mc_hc_w4( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hc_w4( &src[4], i_src, &dst[4], i_dst, i_height );
-}
-static inline void mc_hc_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- mc_hc_w8( &src[0], i_src, &dst[0], i_dst, i_height );
- mc_hc_w8( &src[8], i_src, &dst[8], i_dst, i_height );
-}
-
-/* mc I+H */
-static void mc_xy10_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*4];
- mc_hh_w4( src, i_src, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst, src, i_src, tmp, 4, i_height );
-}
-static void mc_xy10_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*8];
- mc_hh_w8( src, i_src, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst, src, i_src, tmp, 8, i_height );
-}
-static void mc_xy10_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hh_w16( src, i_src, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst, src, i_src, tmp, 16, i_height );
-}
-
-static void mc_xy30_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*4];
- mc_hh_w4( src, i_src, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst, src + 1, i_src, tmp, 4, i_height );
-}
-static void mc_xy30_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*8];
- mc_hh_w8( src, i_src, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst, src + 1, i_src, tmp, 8, i_height );
-}
-static void mc_xy30_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hh_w16( src, i_src, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst, src + 1, i_src, tmp, 16, i_height );
-}
-
-/* mc I+V */
-static void mc_xy01_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*4];
- mc_hv_w4( src, i_src, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst, src, i_src, tmp, 4, i_height );
-}
-static void mc_xy01_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*8];
- mc_hv_w8( src, i_src, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst, src, i_src, tmp, 8, i_height );
-}
-static void mc_xy01_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hv_w16( src, i_src, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst, src, i_src, tmp, 16, i_height );
-}
-
-static void mc_xy03_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*4];
- mc_hv_w4( src, i_src, tmp, 4, i_height );
- pixel_avg_w4( dst, i_dst, src + i_src, i_src, tmp, 4, i_height );
-}
-static void mc_xy03_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*8];
- mc_hv_w8( src, i_src, tmp, 8, i_height );
- pixel_avg_w8( dst, i_dst, src + i_src, i_src, tmp, 8, i_height );
-}
-static void mc_xy03_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp[16*16];
- mc_hv_w16( src, i_src, tmp, 16, i_height );
- pixel_avg_w16( dst, i_dst, src + i_src, i_src, tmp, 16, i_height );
-}
-
-/* H+V */
-static void mc_xy11_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hv_w4( src, i_src, tmp1, 4, i_height );
- mc_hh_w4( src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy11_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hv_w8( src, i_src, tmp1, 8, i_height );
- mc_hh_w8( src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy11_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hv_w16( src, i_src, tmp1, 16, i_height );
- mc_hh_w16( src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy31_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hv_w4( src+1, i_src, tmp1, 4, i_height );
- mc_hh_w4( src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy31_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hv_w8( src+1, i_src, tmp1, 8, i_height );
- mc_hh_w8( src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy31_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hv_w16( src+1, i_src, tmp1, 16, i_height );
- mc_hh_w16( src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy13_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hv_w4( src, i_src, tmp1, 4, i_height );
- mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy13_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hv_w8( src, i_src, tmp1, 8, i_height );
- mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy13_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hv_w16( src, i_src, tmp1, 16, i_height );
- mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy33_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hv_w4( src+1, i_src, tmp1, 4, i_height );
- mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy33_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hv_w8( src+1, i_src, tmp1, 8, i_height );
- mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy33_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hv_w16( src+1, i_src, tmp1, 16, i_height );
- mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy21_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hc_w4( src, i_src, tmp1, 4, i_height );
- mc_hh_w4( src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy21_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hc_w8( src, i_src, tmp1, 8, i_height );
- mc_hh_w8( src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy21_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hc_w16( src, i_src, tmp1, 16, i_height );
- mc_hh_w16( src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy12_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hc_w4( src, i_src, tmp1, 4, i_height );
- mc_hv_w4( src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy12_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hc_w8( src, i_src, tmp1, 8, i_height );
- mc_hv_w8( src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy12_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hc_w16( src, i_src, tmp1, 16, i_height );
- mc_hv_w16( src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy32_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hc_w4( src, i_src, tmp1, 4, i_height );
- mc_hv_w4( src+1, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy32_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hc_w8( src, i_src, tmp1, 8, i_height );
- mc_hv_w8( src+1, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy32_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hc_w16( src, i_src, tmp1, 16, i_height );
- mc_hv_w16( src+1, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void mc_xy23_w4( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*4];
- uint8_t tmp2[16*4];
- mc_hc_w4( src, i_src, tmp1, 4, i_height );
- mc_hh_w4( src+i_src, i_src, tmp2, 4, i_height );
- pixel_avg_w4( dst, i_dst, tmp1, 4, tmp2, 4, i_height );
-}
-static void mc_xy23_w8( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*8];
- uint8_t tmp2[16*8];
- mc_hc_w8( src, i_src, tmp1, 8, i_height );
- mc_hh_w8( src+i_src, i_src, tmp2, 8, i_height );
- pixel_avg_w8( dst, i_dst, tmp1, 8, tmp2, 8, i_height );
-}
-static void mc_xy23_w16( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst, int i_height )
-{
- uint8_t tmp1[16*16];
- uint8_t tmp2[16*16];
- mc_hc_w16( src, i_src, tmp1, 16, i_height );
- mc_hh_w16( src+i_src, i_src, tmp2, 16, i_height );
- pixel_avg_w16( dst, i_dst, tmp1, 16, tmp2, 16, i_height );
-}
-
-static void motion_compensation_luma( uint8_t *src, int i_src,
- uint8_t *dst, int i_dst,
- int mvx,int mvy,
- int i_width, int i_height )
-{
- static const pf_mc_t pf_mc[3][4][4] = /*XXX [dqy][dqx] */
- {
- {
- { mc_copy_w4, mc_xy10_w4, mc_hh_w4, mc_xy30_w4 },
- { mc_xy01_w4, mc_xy11_w4, mc_xy21_w4, mc_xy31_w4 },
- { mc_hv_w4, mc_xy12_w4, mc_hc_w4, mc_xy32_w4 },
- { mc_xy03_w4, mc_xy13_w4, mc_xy23_w4, mc_xy33_w4 },
- },
- {
- { mc_copy_w8, mc_xy10_w8, mc_hh_w8, mc_xy30_w8 },
- { mc_xy01_w8, mc_xy11_w8, mc_xy21_w8, mc_xy31_w8 },
- { mc_hv_w8, mc_xy12_w8, mc_hc_w8, mc_xy32_w8 },
- { mc_xy03_w8, mc_xy13_w8, mc_xy23_w8, mc_xy33_w8 },
- },
- {
- { mc_copy_w16, mc_xy10_w16, mc_hh_w16, mc_xy30_w16 },
- { mc_xy01_w16, mc_xy11_w16, mc_xy21_w16, mc_xy31_w16 },
- { mc_hv_w16, mc_xy12_w16, mc_hc_w16, mc_xy32_w16 },
- { mc_xy03_w16, mc_xy13_w16, mc_xy23_w16, mc_xy33_w16 },
- }
- };
-
- src += (mvy >> 2) * i_src + (mvx >> 2);
- if( i_width == 4 )
- {
- pf_mc[0][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
- }
- else if( i_width == 8 )
- {
- pf_mc[1][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
- }
- else if( i_width == 16 )
- {
- pf_mc[2][mvy&0x03][mvx&0x03]( src, i_src, dst, i_dst, i_height );
- }
-}
-
-void x264_mc_altivec_init( x264_mc_function_t pf[2] )
-{
- pf[MC_LUMA] = motion_compensation_luma;
-}
+++ /dev/null
-/*****************************************************************************
- * mc.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: mc.h,v 1.1 2004/06/03 19:27:07 fenrir Exp $
- *
- * Authors: Eric Petit <titer@m0k.org>
- *
- * 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.
- *****************************************************************************/
-
-#ifndef _PPC_MC_H
-#define _PPC_MC_H 1
-
-void x264_mc_altivec_init( x264_mc_function_t pf[2] );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * pixel.c: h264 encoder
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: pixel.c,v 1.1 2004/06/03 19:27:07 fenrir Exp $
- *
- * Authors: Eric Petit <titer@m0k.org>
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdarg.h>
-
-#ifdef SYS_LINUX
-#include <altivec.h>
-#endif
-
-#include "x264.h"
-#include "../pixel.h"
-#include "pixel.h"
-#include "ppccommon.h"
-
-/* sad routines */
-#define PIXEL_SAD_ALTIVEC( name, lx, ly, a, b ) \
-static int name( uint8_t *pix1, int i_pix1, \
- uint8_t *pix2, int i_pix2 ) \
-{ \
- int y; \
- DECLARE_ALIGNED( int, sum, 16 ); \
- \
- LOAD_ZERO; \
- vector_u8_t pix1v, pix2v; \
- vector_s32_t sumv = zero_s32; \
- for( y = 0; y < ly; y++ ) \
- { \
- LOAD_##lx( pix1, pix1v ); \
- LOAD_##lx( pix2, pix2v ); \
- sumv = (vector_s32_t) vec_sum4s( \
- vec_sub( vec_max( pix1v, pix2v ), \
- vec_min( pix1v, pix2v ) ), \
- (vector_u32_t) sumv ); \
- pix1 += i_pix1; \
- pix2 += i_pix2; \
- } \
- sumv = vec_sum##a( sumv, zero_s32 ); \
- vec_ste( vec_splat( sumv, b ), 0, &sum ); \
- return sum; \
-}
-
-PIXEL_SAD_ALTIVEC( pixel_sad_16x16_altivec, 16, 16, s, 3 )
-PIXEL_SAD_ALTIVEC( pixel_sad_8x16_altivec, 8, 16, 2s, 1 )
-PIXEL_SAD_ALTIVEC( pixel_sad_16x8_altivec, 16, 8, s, 3 )
-PIXEL_SAD_ALTIVEC( pixel_sad_8x8_altivec, 8, 8, 2s, 1 )
-
-/* satd routines */
-static inline int pixel_satd_8x8_altivec( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- int i;
- DECLARE_ALIGNED( int, i_satd, 16 );
-
- LOAD_ZERO;
- vector_s32_t satdv = zero_s32;
- vector_u8_t pix1u8v, pix2u8v;
- vector_s16_t pix1s16v, pix2s16v;
- vector_s16_t diffv[8];
- vector_s16_t tmpv[8];
- vector_s16_t s01v, s23v, d01v, d23v;
-
- /* Diff 8x8 */
- for( i = 0; i < 8; i++ )
- {
- LOAD_8( pix1, pix1u8v );
- LOAD_8( pix2, pix2u8v );
-
- /* u8 -> s16 conversion */
- pix1s16v = (vector_s16_t) vec_mergeh( zero_u8, pix1u8v );
- pix2s16v = (vector_s16_t) vec_mergeh( zero_u8, pix2u8v );
-
- diffv[i] = vec_sub( pix1s16v, pix2s16v );
-
- pix1 += i_pix1;
- pix2 += i_pix2;
- }
-
- /* Hadamar H */
- HADAMAR( &diffv[0], &tmpv[0] );
- HADAMAR( &diffv[4], &tmpv[4] );
-
- /* Transpose */
- TRANSPOSE8x8( tmpv, diffv );
-
- /* Hadamar V */
- HADAMAR( &diffv[0], &tmpv[0] );
- HADAMAR( &diffv[4], &tmpv[4] );
-
- /* Sum of absolute values */
- for( i = 0; i < 8; i++ )
- {
- satdv = vec_sum4s( vec_abs( tmpv[i] ), satdv );
- }
- satdv = vec_sums( satdv, zero_s32 );
-
- /* Done */
- vec_ste( vec_splat( satdv, 3 ), 0, &i_satd );
- return i_satd / 2;
-}
-
-static int pixel_satd_16x8_altivec( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- return pixel_satd_8x8_altivec( &pix1[0], i_pix1,
- &pix2[0], i_pix2 ) +
- pixel_satd_8x8_altivec( &pix1[8], i_pix1,
- &pix2[8], i_pix2 );
-}
-static int pixel_satd_8x16_altivec( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- return pixel_satd_8x8_altivec( &pix1[0], i_pix1,
- &pix2[0], i_pix2 ) +
- pixel_satd_8x8_altivec( &pix1[8*i_pix1], i_pix1,
- &pix2[8*i_pix2], i_pix2 );
-}
-static int pixel_satd_16x16_altivec( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- return pixel_satd_8x8_altivec( &pix1[0], i_pix1,
- &pix2[0], i_pix2 ) +
- pixel_satd_8x8_altivec( &pix1[8], i_pix1,
- &pix2[8], i_pix2 ) +
- pixel_satd_8x8_altivec( &pix1[8*i_pix1], i_pix1,
- &pix2[8*i_pix2], i_pix2 ) +
- pixel_satd_8x8_altivec( &pix1[8*i_pix1+8], i_pix1,
- &pix2[8*i_pix2+8], i_pix2 );
-}
-
-static inline int pixel_satd_4x4_altivec( uint8_t *pix1, int i_pix1,
- uint8_t *pix2, int i_pix2 )
-{
- int i;
- DECLARE_ALIGNED( int, i_satd, 16 );
-
- LOAD_ZERO;
- vector_s32_t satdv = zero_s32;
- vector_u8_t pix1u8v, pix2u8v;
- vector_s16_t pix1s16v, pix2s16v;
- vector_s16_t diffv[4];
- vector_s16_t tmpv[4];
- vector_s16_t s01v, s23v, d01v, d23v;
-
- /* Diff 4x8 */
- for( i = 0; i < 4; i++ )
- {
- LOAD_4( pix1, pix1u8v );
- LOAD_4( pix2, pix2u8v );
-
- /* u8 -> s16 conversion */
- pix1s16v = (vector_s16_t) vec_mergeh( zero_u8, pix1u8v );
- pix2s16v = (vector_s16_t) vec_mergeh( zero_u8, pix2u8v );
-
- diffv[i] = vec_sub( pix1s16v, pix2s16v );
-
- pix1 += i_pix1;
- pix2 += i_pix2;
- }
-
- /* Hadamar H */
- HADAMAR( diffv, tmpv );
-
- /* Transpose */
- TRANSPOSE4x4( tmpv, diffv );
-
- /* Hadamar V */
- HADAMAR( diffv, tmpv );
-
- /* Sum of absolute values */
- for( i = 0; i < 4; i++ )
- {
- satdv = vec_sum4s( vec_abs( tmpv[i] ), satdv );
- }
- satdv = vec_sum2s( satdv, zero_s32 );
-
- /* Done */
- vec_ste( vec_splat( satdv, 1 ), 0, &i_satd );
- return i_satd / 2;
-}
-
-/****************************************************************************
- * x264_pixel_init:
- ****************************************************************************/
-void x264_pixel_altivec_init( x264_pixel_function_t *pixf )
-{
- pixf->sad[PIXEL_16x16] = pixel_sad_16x16_altivec;
- pixf->sad[PIXEL_8x16] = pixel_sad_8x16_altivec;
- pixf->sad[PIXEL_16x8] = pixel_sad_16x8_altivec;
- pixf->sad[PIXEL_8x8] = pixel_sad_8x8_altivec;
-
- pixf->satd[PIXEL_16x16] = pixel_satd_16x16_altivec;
- pixf->satd[PIXEL_8x16] = pixel_satd_8x16_altivec;
- pixf->satd[PIXEL_16x8] = pixel_satd_16x8_altivec;
- pixf->satd[PIXEL_8x8] = pixel_satd_8x8_altivec;
- pixf->satd[PIXEL_4x4] = pixel_satd_4x4_altivec;
-}
+++ /dev/null
-/*****************************************************************************
- * mc.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: pixel.h,v 1.1 2004/06/03 19:27:07 fenrir Exp $
- *
- * Authors: Eric Petit <titer@m0k.org>
- *
- * 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.
- *****************************************************************************/
-
-#ifndef _PPC_PIXEL_H
-#define _PPC_PIXEL_H 1
-
-void x264_pixel_altivec_init( x264_pixel_function_t *pixf );
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * ppccommon.h: h264 encoder
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: ppccommon.h,v 1.1 2004/06/03 19:27:07 fenrir Exp $
- *
- * Authors: Eric Petit <titer@m0k.org>
- *
- * 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.
- *****************************************************************************/
-
-/* Handy */
-#define vector_u8_t vector unsigned char
-#define vector_s16_t vector signed short
-#define vector_u32_t vector unsigned int
-#define vector_s32_t vector signed int
-
-#define LOAD_ZERO vector_s32_t zero = vec_splat_s32( 0 )
-#define zero_u8 (vector_u8_t) zero
-#define zero_s16 (vector_s16_t) zero
-#define zero_s32 (vector_s32_t) zero
-
-#define CONVERT_U8_TO_S16( a ) \
- a = (vector_s16_t) vec_mergeh( zero_u8, (vector_u8_t) a )
-
-/* Macros to load aligned or unaligned data without risking buffer
- overflows. */
-#define LOAD_16( p, v ) \
- if( (long) p & 0xF ) \
- { \
- v = vec_perm( vec_ld( 0, p ), vec_ld( 16, p ), \
- vec_lvsl( 0, p ) ); \
- } \
- else \
- { \
- v = vec_ld( 0, p ); \
- }
-
-#define LOAD_8( p, v ) \
- if( !( (long) p & 0xF ) ) \
- { \
- v = vec_ld( 0, p ); \
- } \
- else if( ( (long) p & 0xF ) < 9 ) \
- { \
- v = vec_perm( vec_ld( 0, p ), (vector unsigned char) zero, \
- vec_lvsl( 0, p ) ); \
- } \
- else \
- { \
- v = vec_perm( vec_ld( 0, p ), vec_ld( 16, p ), \
- vec_lvsl( 0, p ) ); \
- }
-
-#define LOAD_4( p, v ) \
- if( !( (long) p & 0xF ) ) \
- { \
- v = vec_ld( 0, p ); \
- } \
- else if( ( (long) p & 0xF ) < 13 ) \
- { \
- v = vec_perm( vec_ld( 0, p ), (vector unsigned char) zero, \
- vec_lvsl( 0, p ) ); \
- } \
- else \
- { \
- v = vec_perm( vec_ld( 0, p ), vec_ld( 16, p ), \
- vec_lvsl( 0, p ) ); \
- }
-
-/* Store aligned or unaligned data */
-#define STORE_16( v, p ) \
- if( (long) p & 0xF ) \
- { \
- vector unsigned char tmp1, tmp2; \
- vector unsigned char align, mask; \
- tmp1 = vec_ld( 0, p ); \
- tmp2 = vec_ld( 16, p ); \
- align = vec_lvsr( 0, p ); \
- mask = vec_perm( (vector unsigned char) {0}, \
- (vector unsigned char) {1}, \
- align); \
- v = vec_perm( v, v, align); \
- tmp1 = vec_sel( tmp1, v, mask ); \
- tmp2 = vec_sel( v, tmp2, mask ); \
- vec_st( tmp1, 0, p ); \
- vec_st( tmp2, 16, p ); \
- } \
- else \
- { \
- vec_st( v, 0, p ); \
- }
-
-/* Transpose 8x8 (vector_s16_t [8]) */
-#define TRANSPOSE8x8( a, b ) \
- b[0] = vec_mergeh( a[0], a[4] ); \
- b[1] = vec_mergel( a[0], a[4] ); \
- b[2] = vec_mergeh( a[1], a[5] ); \
- b[3] = vec_mergel( a[1], a[5] ); \
- b[4] = vec_mergeh( a[2], a[6] ); \
- b[5] = vec_mergel( a[2], a[6] ); \
- b[6] = vec_mergeh( a[3], a[7] ); \
- b[7] = vec_mergel( a[3], a[7] ); \
- a[0] = vec_mergeh( b[0], b[4] ); \
- a[1] = vec_mergel( b[0], b[4] ); \
- a[2] = vec_mergeh( b[1], b[5] ); \
- a[3] = vec_mergel( b[1], b[5] ); \
- a[4] = vec_mergeh( b[2], b[6] ); \
- a[5] = vec_mergel( b[2], b[6] ); \
- a[6] = vec_mergeh( b[3], b[7] ); \
- a[7] = vec_mergel( b[3], b[7] ); \
- b[0] = vec_mergeh( a[0], a[4] ); \
- b[1] = vec_mergel( a[0], a[4] ); \
- b[2] = vec_mergeh( a[1], a[5] ); \
- b[3] = vec_mergel( a[1], a[5] ); \
- b[4] = vec_mergeh( a[2], a[6] ); \
- b[5] = vec_mergel( a[2], a[6] ); \
- b[6] = vec_mergeh( a[3], a[7] ); \
- b[7] = vec_mergel( a[3], a[7] );
-
-/* Transpose 4x4 (vector_s16_t [4]) */
-#define TRANSPOSE4x4( a, b ) \
- (b)[0] = vec_mergeh( (a)[0], zero_s16 ); \
- (b)[1] = vec_mergeh( (a)[1], zero_s16 ); \
- (b)[2] = vec_mergeh( (a)[2], zero_s16 ); \
- (b)[3] = vec_mergeh( (a)[3], zero_s16 ); \
- (a)[0] = vec_mergeh( (b)[0], (b)[2] ); \
- (a)[1] = vec_mergel( (b)[0], (b)[2] ); \
- (a)[2] = vec_mergeh( (b)[1], (b)[3] ); \
- (a)[3] = vec_mergel( (b)[1], (b)[3] ); \
- (b)[0] = vec_mergeh( (a)[0], (a)[2] ); \
- (b)[1] = vec_mergel( (a)[0], (a)[2] ); \
- (b)[2] = vec_mergeh( (a)[1], (a)[3] ); \
- (b)[3] = vec_mergel( (a)[1], (a)[3] );
-
-/* Hadamar (vector_s16_t [4]) */
-#define HADAMAR( a, b ) \
- s01v = vec_add( (a)[0], (a)[1] ); \
- s23v = vec_add( (a)[2], (a)[3] ); \
- d01v = vec_sub( (a)[0], (a)[1] ); \
- d23v = vec_sub( (a)[2], (a)[3] ); \
- (b)[0] = vec_add( s01v, s23v ); \
- (b)[1] = vec_sub( s01v, s23v ); \
- (b)[2] = vec_sub( d01v, d23v ); \
- (b)[3] = vec_add( d01v, d23v );
-
+++ /dev/null
-/*****************************************************************************
- * predict.c: h264 encoder
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: predict.c,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-/* XXX predict4x4 are inspired from ffmpeg h264 decoder
- */
-
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#else
-#include <inttypes.h>
-#endif
-#include <stdlib.h>
-#include <stdarg.h>
-
-#include "x264.h"
-#include "predict.h"
-
-#ifdef _MSC_VER
-#undef HAVE_MMXEXT /* not finished now */
-#endif
-#ifdef HAVE_MMXEXT
-# include "i386/predict.h"
-#endif
-
-static inline int clip_uint8( int a )
-{
- if (a&(~255))
- return (-a)>>31;
- else
- return a;
-}
-
-/****************************************************************************
- * 16x16 prediction for intra block DC, H, V, P
- ****************************************************************************/
-static void predict_16x16_dc( uint8_t *src, int i_stride )
-{
- int dc = 0;
- int i, j;
-
- /* calculate DC value */
- for( i = 0; i < 16; i++ )
- {
- dc += src[-1 + i * i_stride];
- dc += src[i - i_stride];
- }
- dc = ( dc + 16 ) >> 5;
-
- for( i = 0; i < 16; i++ )
- {
- for( j = 0; j < 16; j++ )
- {
- src[j] = dc;
- }
- src += i_stride;
- }
-}
-static void predict_16x16_dc_left( uint8_t *src, int i_stride )
-{
- int dc = 0;
- int i,j;
-
- for( i = 0; i < 16; i++ )
- {
- dc += src[-1 + i * i_stride];
- }
- dc = ( dc + 8 ) >> 4;
-
- for( i = 0; i < 16; i++ )
- {
- for( j = 0; j < 16; j++ )
- {
- src[j] = dc;
- }
- src += i_stride;
- }
-}
-static void predict_16x16_dc_top( uint8_t *src, int i_stride )
-{
- int dc = 0;
- int i,j;
-
- for( i = 0; i < 16; i++ )
- {
- dc += src[i - i_stride];
- }
- dc = ( dc + 8 ) >> 4;
-
- for( i = 0; i < 16; i++ )
- {
- for( j = 0; j < 16; j++ )
- {
- src[j] = dc;
- }
- src += i_stride;
- }
-}
-static void predict_16x16_dc_128( uint8_t *src, int i_stride )
-{
- int i,j;
-
- for( i = 0; i < 16; i++ )
- {
- for( j = 0; j < 16; j++ )
- {
- src[j] = 128;
- }
- src += i_stride;
- }
-}
-static void predict_16x16_h( uint8_t *src, int i_stride )
-{
- int i,j;
-
- for( i = 0; i < 16; i++ )
- {
- uint8_t v;
-
- v = src[-1];
- for( j = 0; j < 16; j++ )
- {
- src[j] = v;
- }
- src += i_stride;
-
- }
-}
-static void predict_16x16_v( uint8_t *src, int i_stride )
-{
- int i,j;
-
- for( i = 0; i < 16; i++ )
- {
- for( j = 0; j < 16; j++ )
- {
- src[i * i_stride +j] = src[j - i_stride];
- }
- }
-}
-static void predict_16x16_p( uint8_t *src, int i_stride )
-{
- int x, y, i;
- int a, b, c;
- int H = 0;
- int V = 0;
- int i00;
-
- /* calcule H and V */
- for( i = 0; i <= 7; i++ )
- {
- H += ( i + 1 ) * ( src[ 8 + i - i_stride ] - src[6 -i -i_stride] );
- V += ( i + 1 ) * ( src[-1 + (8+i)*i_stride] - src[-1 + (6-i)*i_stride] );
- }
-
- a = 16 * ( src[-1 + 15*i_stride] + src[15 - i_stride] );
- b = ( 5 * H + 32 ) >> 6;
- c = ( 5 * V + 32 ) >> 6;
-
- i00 = a - b * 7 - c * 7 + 16;
-
- for( y = 0; y < 16; y++ )
- {
- for( x = 0; x < 16; x++ )
- {
- int pix;
-
- pix = (i00+b*x)>>5;
-
- src[x] = clip_uint8( pix );
- }
- src += i_stride;
- i00 += c;
- }
-}
-
-
-/****************************************************************************
- * 8x8 prediction for intra chroma block DC, H, V, P
- ****************************************************************************/
-static void predict_8x8_dc_128( uint8_t *src, int i_stride )
-{
- int x,y;
-
- for( y = 0; y < 8; y++ )
- {
- for( x = 0; x < 8; x++ )
- {
- src[x] = 128;
- }
- src += i_stride;
- }
-}
-static void predict_8x8_dc_left( uint8_t *src, int i_stride )
-{
- int x,y;
- int dc0 = 0, dc1 = 0;
-
- for( y = 0; y < 4; y++ )
- {
- dc0 += src[y * i_stride - 1];
- dc1 += src[(y+4) * i_stride - 1];
- }
- dc0 = ( dc0 + 2 ) >> 2;
- dc1 = ( dc1 + 2 ) >> 2;
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 8; x++ )
- {
- src[ x] = dc0;
- src[4*i_stride+x] = dc1;
- }
- src += i_stride;
- }
-}
-static void predict_8x8_dc_top( uint8_t *src, int i_stride )
-{
- int x,y;
- int dc0 = 0, dc1 = 0;
-
- for( x = 0; x < 4; x++ )
- {
- dc0 += src[x - i_stride];
- dc1 += src[x + 4 - i_stride];
- }
- dc0 = ( dc0 + 2 ) >> 2;
- dc1 = ( dc1 + 2 ) >> 2;
-
- for( y = 0; y < 8; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- src[x ] = dc0;
- src[x + 4] = dc1;
- }
- src += i_stride;
- }
-}
-static void predict_8x8_dc( uint8_t *src, int i_stride )
-{
- int x,y;
- int s0 = 0, s1 = 0, s2 = 0, s3 = 0;
- int dc0, dc1, dc2, dc3;
- int i;
-
- /* First do :
- s0 s1
- s2
- s3
- */
- for( i = 0; i < 4; i++ )
- {
- s0 += src[i - i_stride];
- s1 += src[i + 4 - i_stride];
- s2 += src[-1 + i * i_stride];
- s3 += src[-1 + (i+4)*i_stride];
- }
- /* now calculate
- dc0 dc1
- dc2 dc3
- */
- dc0 = ( s0 + s2 + 4 ) >> 3;
- dc1 = ( s1 + 2 ) >> 2;
- dc2 = ( s3 + 2 ) >> 2;
- dc3 = ( s1 + s3 + 4 ) >> 3;
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- src[ x ] = dc0;
- src[ x + 4] = dc1;
- src[4*i_stride + x ] = dc2;
- src[4*i_stride + x + 4] = dc3;
- }
- src += i_stride;
- }
-}
-
-static void predict_8x8_h( uint8_t *src, int i_stride )
-{
- int i,j;
-
- for( i = 0; i < 8; i++ )
- {
- uint8_t v;
-
- v = src[-1];
-
- for( j = 0; j < 8; j++ )
- {
- src[j] = v;
- }
- src += i_stride;
- }
-}
-static void predict_8x8_v( uint8_t *src, int i_stride )
-{
- int i,j;
-
- for( i = 0; i < 8; i++ )
- {
- for( j = 0; j < 8; j++ )
- {
- src[i * i_stride +j] = src[j - i_stride];
- }
- }
-}
-
-static void predict_8x8_p( uint8_t *src, int i_stride )
-{
- int i;
- int x,y;
- int a, b, c;
- int H = 0;
- int V = 0;
- int i00;
-
- for( i = 0; i < 4; i++ )
- {
- H += ( i + 1 ) * ( src[4+i - i_stride] - src[2 - i -i_stride] );
- V += ( i + 1 ) * ( src[-1 +(i+4)*i_stride] - src[-1+(2-i)*i_stride] );
- }
-
- a = 16 * ( src[-1+7*i_stride] + src[7 - i_stride] );
- b = ( 17 * H + 16 ) >> 5;
- c = ( 17 * V + 16 ) >> 5;
- i00 = a -3*b -3*c + 16;
-
- for( y = 0; y < 8; y++ )
- {
- for( x = 0; x < 8; x++ )
- {
- int pix;
-
- pix = (i00 +b*x) >> 5;
- src[x] = clip_uint8( pix );
- }
- src += i_stride;
- i00 += c;
- }
-}
-
-/****************************************************************************
- * 4x4 prediction for intra luma block DC, H, V, P
- ****************************************************************************/
-static void predict_4x4_dc_128( uint8_t *src, int i_stride )
-{
- int x,y;
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- src[x] = 128;
- }
- src += i_stride;
- }
-}
-static void predict_4x4_dc_left( uint8_t *src, int i_stride )
-{
- int x,y;
- int dc = ( src[-1+0*i_stride] + src[-1+i_stride]+
- src[-1+2*i_stride] + src[-1+3*i_stride] + 2 ) >> 2;
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- src[x] = dc;
- }
- src += i_stride;
- }
-}
-static void predict_4x4_dc_top( uint8_t *src, int i_stride )
-{
- int x,y;
- int dc = ( src[0 - i_stride] + src[1 - i_stride] +
- src[2 - i_stride] + src[3 - i_stride] + 2 ) >> 2;
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- src[x] = dc;
- }
- src += i_stride;
- }
-}
-static void predict_4x4_dc( uint8_t *src, int i_stride )
-{
- int x,y;
- int dc = ( src[-1+0*i_stride] + src[-1+i_stride]+
- src[-1+2*i_stride] + src[-1+3*i_stride] +
- src[0 - i_stride] + src[1 - i_stride] +
- src[2 - i_stride] + src[3 - i_stride] + 4 ) >> 3;
-
- for( y = 0; y < 4; y++ )
- {
- for( x = 0; x < 4; x++ )
- {
- src[x] = dc;
- }
- src += i_stride;
- }
-}
-static void predict_4x4_h( uint8_t *src, int i_stride )
-{
- int i,j;
-
- for( i = 0; i < 4; i++ )
- {
- uint8_t v;
-
- v = src[-1];
-
- for( j = 0; j < 4; j++ )
- {
- src[j] = v;
- }
- src += i_stride;
- }
-}
-static void predict_4x4_v( uint8_t *src, int i_stride )
-{
- int i,j;
-
- for( i = 0; i < 4; i++ )
- {
- for( j = 0; j < 4; j++ )
- {
- src[i * i_stride +j] = src[j - i_stride];
- }
- }
-}
-
-#define PREDICT_4x4_LOAD_LEFT \
- const int l0 = src[-1+0*i_stride]; \
- const int l1 = src[-1+1*i_stride]; \
- const int l2 = src[-1+2*i_stride]; \
- const int l3 = src[-1+3*i_stride];
-
-#define PREDICT_4x4_LOAD_TOP \
- const int t0 = src[0-1*i_stride]; \
- const int t1 = src[1-1*i_stride]; \
- const int t2 = src[2-1*i_stride]; \
- const int t3 = src[3-1*i_stride];
-
-#define PREDICT_4x4_LOAD_TOP_RIGHT \
- const int t4 = src[4-1*i_stride]; \
- const int t5 = src[5-1*i_stride]; \
- const int t6 = src[6-1*i_stride]; \
- const int t7 = src[7-1*i_stride];
-
-
-static void predict_4x4_ddl( uint8_t *src, int i_stride )
-{
- PREDICT_4x4_LOAD_TOP
- PREDICT_4x4_LOAD_TOP_RIGHT
-
- src[0*i_stride+0] = ( t0 + 2*t1+ t2 + 2 ) >> 2;
-
- src[0*i_stride+1] =
- src[1*i_stride+0] = ( t1 + 2*t2+ t3 + 2 ) >> 2;
-
- src[0*i_stride+2] =
- src[1*i_stride+1] =
- src[2*i_stride+0] = ( t2 + 2*t3+ t4 + 2 ) >> 2;
-
- src[0*i_stride+3] =
- src[1*i_stride+2] =
- src[2*i_stride+1] =
- src[3*i_stride+0] = ( t3 + 2*t4+ t5 + 2 ) >> 2;
-
- src[1*i_stride+3] =
- src[2*i_stride+2] =
- src[3*i_stride+1] = ( t4 + 2*t5+ t6 + 2 ) >> 2;
-
- src[2*i_stride+3] =
- src[3*i_stride+2] = ( t5 + 2*t6+ t7 + 2 ) >> 2;
-
- src[3*i_stride+3] = ( t6 + 3 * t7 + 2 ) >> 2;
-}
-static void predict_4x4_ddr( uint8_t *src, int i_stride )
-{
- const int lt = src[-1-i_stride];
- PREDICT_4x4_LOAD_LEFT
- PREDICT_4x4_LOAD_TOP
-
- src[0*i_stride+0] =
- src[1*i_stride+1] =
- src[2*i_stride+2] =
- src[3*i_stride+3] = ( t0 + 2*lt +l0 + 2 ) >> 2;
-
- src[0*i_stride+1] =
- src[1*i_stride+2] =
- src[2*i_stride+3] = ( lt + 2 * t0 + t1 + 2 ) >> 2;
-
- src[0*i_stride+2] =
- src[1*i_stride+3] = ( t0 + 2 * t1 + t2 + 2 ) >> 2;
-
- src[0*i_stride+3] = ( t1 + 2 * t2 + t3 + 2 ) >> 2;
-
- src[1*i_stride+0] =
- src[2*i_stride+1] =
- src[3*i_stride+2] = ( lt + 2 * l0 + l1 + 2 ) >> 2;
-
- src[2*i_stride+0] =
- src[3*i_stride+1] = ( l0 + 2 * l1 + l2 + 2 ) >> 2;
-
- src[3*i_stride+0] = ( l1 + 2 * l2 + l3 + 2 ) >> 2;
-}
-
-static void predict_4x4_vr( uint8_t *src, int i_stride )
-{
- const int lt = src[-1-i_stride];
- PREDICT_4x4_LOAD_LEFT
- PREDICT_4x4_LOAD_TOP
- /* produce warning as l3 is unused */
-
- src[0*i_stride+0]=
- src[2*i_stride+1]= ( lt + t0 + 1 ) >> 1;
-
- src[0*i_stride+1]=
- src[2*i_stride+2]= ( t0 + t1 + 1 ) >> 1;
-
- src[0*i_stride+2]=
- src[2*i_stride+3]= ( t1 + t2 + 1 ) >> 1;
-
- src[0*i_stride+3]= ( t2 + t3 + 1 ) >> 1;
-
- src[1*i_stride+0]=
- src[3*i_stride+1]= ( l0 + 2 * lt + t0 + 2 ) >> 2;
-
- src[1*i_stride+1]=
- src[3*i_stride+2]= ( lt + 2 * t0 + t1 + 2 ) >> 2;
-
- src[1*i_stride+2]=
- src[3*i_stride+3]= ( t0 + 2 * t1 + t2 + 2) >> 2;
-
- src[1*i_stride+3]= ( t1 + 2 * t2 + t3 + 2 ) >> 2;
- src[2*i_stride+0]= ( lt + 2 * l0 + l1 + 2 ) >> 2;
- src[3*i_stride+0]= ( l0 + 2 * l1 + l2 + 2 ) >> 2;
-}
-
-static void predict_4x4_hd( uint8_t *src, int i_stride )
-{
- const int lt= src[-1-1*i_stride];
- PREDICT_4x4_LOAD_LEFT
- PREDICT_4x4_LOAD_TOP
- /* produce warning as t3 is unused */
-
- src[0*i_stride+0]=
- src[1*i_stride+2]= ( lt + l0 + 1 ) >> 1;
- src[0*i_stride+1]=
- src[1*i_stride+3]= ( l0 + 2 * lt + t0 + 2 ) >> 2;
- src[0*i_stride+2]= ( lt + 2 * t0 + t1 + 2 ) >> 2;
- src[0*i_stride+3]= ( t0 + 2 * t1 + t2 + 2 ) >> 2;
- src[1*i_stride+0]=
- src[2*i_stride+2]= ( l0 + l1 + 1 ) >> 1;
- src[1*i_stride+1]=
- src[2*i_stride+3]= ( lt + 2 * l0 + l1 + 2 ) >> 2;
- src[2*i_stride+0]=
- src[3*i_stride+2]= ( l1 + l2+ 1 ) >> 1;
- src[2*i_stride+1]=
- src[3*i_stride+3]= ( l0 + 2 * l1 + l2 + 2 ) >> 2;
- src[3*i_stride+0]= ( l2 + l3 + 1 ) >> 1;
- src[3*i_stride+1]= ( l1 + 2 * l2 + l3 + 2 ) >> 2;
-}
-
-static void predict_4x4_vl( uint8_t *src, int i_stride )
-{
- PREDICT_4x4_LOAD_TOP
- PREDICT_4x4_LOAD_TOP_RIGHT
- /* produce warning as t7 is unused */
-
- src[0*i_stride+0]= ( t0 + t1 + 1 ) >> 1;
- src[0*i_stride+1]=
- src[2*i_stride+0]= ( t1 + t2 + 1 ) >> 1;
- src[0*i_stride+2]=
- src[2*i_stride+1]= ( t2 + t3 + 1 ) >> 1;
- src[0*i_stride+3]=
- src[2*i_stride+2]= ( t3 + t4+ 1 ) >> 1;
- src[2*i_stride+3]= ( t4 + t5+ 1 ) >> 1;
- src[1*i_stride+0]= ( t0 + 2 * t1 + t2 + 2 ) >> 2;
- src[1*i_stride+1]=
- src[3*i_stride+0]= ( t1 + 2 * t2 + t3 + 2 ) >> 2;
- src[1*i_stride+2]=
- src[3*i_stride+1]= ( t2 + 2 * t3 + t4 + 2 ) >> 2;
- src[1*i_stride+3]=
- src[3*i_stride+2]= ( t3 + 2 * t4 + t5 + 2 ) >> 2;
- src[3*i_stride+3]= ( t4 + 2 * t5 + t6 + 2 ) >> 2;
-}
-
-static void predict_4x4_hu( uint8_t *src, int i_stride )
-{
- PREDICT_4x4_LOAD_LEFT
-
- src[0*i_stride+0]= ( l0 + l1 + 1 ) >> 1;
- src[0*i_stride+1]= ( l0 + 2 * l1 + l2 + 2 ) >> 2;
-
- src[0*i_stride+2]=
- src[1*i_stride+0]= ( l1 + l2 + 1 ) >> 1;
-
- src[0*i_stride+3]=
- src[1*i_stride+1]= ( l1 + 2*l2 + l3 + 2 ) >> 2;
-
- src[1*i_stride+2]=
- src[2*i_stride+0]= ( l2 + l3 + 1 ) >> 1;
-
- src[1*i_stride+3]=
- src[2*i_stride+1]= ( l2 + 2 * l3 + l3 + 2 ) >> 2;
-
- src[2*i_stride+3]=
- src[3*i_stride+1]=
- src[3*i_stride+0]=
- src[2*i_stride+2]=
- src[3*i_stride+2]=
- src[3*i_stride+3]= l3;
-}
-
-/****************************************************************************
- * Exported functions:
- ****************************************************************************/
-void x264_predict_16x16_init( int cpu, x264_predict_t pf[7] )
-{
- pf[I_PRED_16x16_V ] = predict_16x16_v;
- pf[I_PRED_16x16_H ] = predict_16x16_h;
- pf[I_PRED_16x16_DC] = predict_16x16_dc;
- pf[I_PRED_16x16_P ] = predict_16x16_p;
- pf[I_PRED_16x16_DC_LEFT]= predict_16x16_dc_left;
- pf[I_PRED_16x16_DC_TOP ]= predict_16x16_dc_top;
- pf[I_PRED_16x16_DC_128 ]= predict_16x16_dc_128;
-
-#ifdef HAVE_MMXEXT
- if( cpu&X264_CPU_MMXEXT )
- {
- x264_predict_16x16_init_mmxext( pf );
- }
-#endif
-}
-
-void x264_predict_8x8_init( int cpu, x264_predict_t pf[7] )
-{
- pf[I_PRED_CHROMA_V ] = predict_8x8_v;
- pf[I_PRED_CHROMA_H ] = predict_8x8_h;
- pf[I_PRED_CHROMA_DC] = predict_8x8_dc;
- pf[I_PRED_CHROMA_P ] = predict_8x8_p;
- pf[I_PRED_CHROMA_DC_LEFT]= predict_8x8_dc_left;
- pf[I_PRED_CHROMA_DC_TOP ]= predict_8x8_dc_top;
- pf[I_PRED_CHROMA_DC_128 ]= predict_8x8_dc_128;
-
-#ifdef HAVE_MMXEXT
- if( cpu&X264_CPU_MMXEXT )
- {
- x264_predict_8x8_init_mmxext( pf );
- }
-#endif
-}
-
-void x264_predict_4x4_init( int cpu, x264_predict_t pf[12] )
-{
- pf[I_PRED_4x4_V] = predict_4x4_v;
- pf[I_PRED_4x4_H] = predict_4x4_h;
- pf[I_PRED_4x4_DC] = predict_4x4_dc;
- pf[I_PRED_4x4_DDL] = predict_4x4_ddl;
- pf[I_PRED_4x4_DDR] = predict_4x4_ddr;
- pf[I_PRED_4x4_VR] = predict_4x4_vr;
- pf[I_PRED_4x4_HD] = predict_4x4_hd;
- pf[I_PRED_4x4_VL] = predict_4x4_vl;
- pf[I_PRED_4x4_HU] = predict_4x4_hu;
- pf[I_PRED_4x4_DC_LEFT]= predict_4x4_dc_left;
- pf[I_PRED_4x4_DC_TOP] = predict_4x4_dc_top;
- pf[I_PRED_4x4_DC_128] = predict_4x4_dc_128;
-
-#ifdef HAVE_MMXEXT
- if( cpu&X264_CPU_MMXEXT )
- {
- x264_predict_4x4_init_mmxext( pf );
- }
-#endif
-}
-
+++ /dev/null
-/*****************************************************************************
- * predict.h: h264 encoder library
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: predict.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _PREDICT_H
-#define _PREDICT_H 1
-
-typedef void (*x264_predict_t)( uint8_t *src, int i_stride );
-
-enum intra_chroma_pred_e
-{
- I_PRED_CHROMA_DC = 0,
- I_PRED_CHROMA_H = 1,
- I_PRED_CHROMA_V = 2,
- I_PRED_CHROMA_P = 3,
-
- I_PRED_CHROMA_DC_LEFT = 4,
- I_PRED_CHROMA_DC_TOP = 5,
- I_PRED_CHROMA_DC_128 = 6
-};
-static const int x264_mb_pred_mode8x8_fix[7] =
-{
- I_PRED_CHROMA_DC, I_PRED_CHROMA_H, I_PRED_CHROMA_V, I_PRED_CHROMA_P,
- I_PRED_CHROMA_DC, I_PRED_CHROMA_DC,I_PRED_CHROMA_DC
-};
-
-enum intra16x16_pred_e
-{
- I_PRED_16x16_V = 0,
- I_PRED_16x16_H = 1,
- I_PRED_16x16_DC = 2,
- I_PRED_16x16_P = 3,
-
- I_PRED_16x16_DC_LEFT = 4,
- I_PRED_16x16_DC_TOP = 5,
- I_PRED_16x16_DC_128 = 6,
-};
-static const int x264_mb_pred_mode16x16_fix[7] =
-{
- I_PRED_16x16_V, I_PRED_16x16_H, I_PRED_16x16_DC, I_PRED_16x16_P,
- I_PRED_16x16_DC,I_PRED_16x16_DC,I_PRED_16x16_DC
-};
-
-enum intra4x4_pred_e
-{
- I_PRED_4x4_V = 0,
- I_PRED_4x4_H = 1,
- I_PRED_4x4_DC = 2,
- I_PRED_4x4_DDL= 3,
- I_PRED_4x4_DDR= 4,
- I_PRED_4x4_VR = 5,
- I_PRED_4x4_HD = 6,
- I_PRED_4x4_VL = 7,
- I_PRED_4x4_HU = 8,
-
- I_PRED_4x4_DC_LEFT = 9,
- I_PRED_4x4_DC_TOP = 10,
- I_PRED_4x4_DC_128 = 11,
-};
-static const int x264_mb_pred_mode4x4_fix[12] =
-{
- I_PRED_4x4_V, I_PRED_4x4_H, I_PRED_4x4_DC,
- I_PRED_4x4_DDL, I_PRED_4x4_DDR, I_PRED_4x4_VR,
- I_PRED_4x4_HD, I_PRED_4x4_VL, I_PRED_4x4_HU,
- I_PRED_4x4_DC, I_PRED_4x4_DC, I_PRED_4x4_DC
-};
-
-void x264_predict_16x16_init ( int cpu, x264_predict_t pf[7] );
-void x264_predict_8x8_init ( int cpu, x264_predict_t pf[7] );
-void x264_predict_4x4_init ( int cpu, x264_predict_t pf[12] );
-
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * set.h: h264 encoder
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: set.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-#ifndef _SET_H
-#define _SET_H 1
-
-enum profile_e
-{
- PROFILE_BASELINE = 66,
- PROFILE_MAIN = 77,
- PROFILE_EXTENTED = 88
-};
-
-typedef struct
-{
- int i_id;
-
- int i_profile_idc;
- int i_level_idc;
-
- int b_constraint_set0;
- int b_constraint_set1;
- int b_constraint_set2;
-
- int i_log2_max_frame_num;
-
- int i_poc_type;
- /* poc 0 */
- int i_log2_max_poc_lsb;
- /* poc 1 */
- int b_delta_pic_order_always_zero;
- int i_offset_for_non_ref_pic;
- int i_offset_for_top_to_bottom_field;
- int i_num_ref_frames_in_poc_cycle;
- int i_offset_for_ref_frame[256];
-
- int i_num_ref_frames;
- int b_gaps_in_frame_num_value_allowed;
- int i_mb_width;
- int i_mb_height;
- int b_frame_mbs_only;
- int b_mb_adaptive_frame_field;
- int b_direct8x8_inference;
-
- int b_crop;
- struct
- {
- int i_left;
- int i_right;
- int i_top;
- int i_bottom;
- } crop;
-
- int b_vui;
- struct
- {
- int b_aspect_ratio_info_present;
- int i_sar_width;
- int i_sar_height;
-
- int b_timing_info_present;
- int i_num_units_in_tick;
- int i_time_scale;
- int b_fixed_frame_rate;
-
- /* FIXME to complete */
- } vui;
-} x264_sps_t;
-
-typedef struct
-{
- int i_id;
- int i_sps_id;
-
- int b_cabac;
-
- int b_pic_order;
- int i_num_slice_groups;
-
- int i_slice_group_map_type;
- /* i_slice_group_map_type == 0 */
- int i_run_length[256]; /* FIXME */
- /* i_slice_group_map_type == 2 */
- int i_top_left[256]; /* FIXME */
- int i_bottom_right[256]; /* FIXME */
- /* i_slice_group_map_type == 3, 4, 5 */
- int b_slice_group_change_direction;
- int i_slice_group_change_rate;
- /* i_slice_group_map_type == 6 */
- int i_pic_size_in_map_units;
- int i_slice_group_id[256]; /* FIXME */
-
- int i_num_ref_idx_l0_active;
- int i_num_ref_idx_l1_active;
-
- int b_weighted_pred;
- int b_weighted_bipred;
-
- int i_pic_init_qp;
- int i_pic_init_qs;
-
- int i_chroma_qp_index_offset;
-
- int b_deblocking_filter_control;
- int b_constrained_intra_pred;
- int b_redundant_pic_cnt;
-} x264_pps_t;
-
-#endif
+++ /dev/null
-/*****************************************************************************
- * vlc.h : vlc table
- *****************************************************************************
- * Copyright (C) 2003 Laurent Aimar
- * $Id: vlc.h,v 1.1 2004/06/03 19:27:07 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.
- *****************************************************************************/
-
-typedef struct
-{
- int i_bits;
- int i_size;
-} vlc_t;
-
-/* XXX: don't forget to change it if you change vlc_t */
-#define MKVLC( a, b ) { a, b }
-static const vlc_t x264_coeff_token[5][17*4] =
-{
- /* table 0 */
- {
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x5, 6 ), /* str=000101 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x7, 8 ), /* str=00000111 */
- MKVLC( 0x4, 6 ), /* str=000100 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x7, 9 ), /* str=000000111 */
- MKVLC( 0x6, 8 ), /* str=00000110 */
- MKVLC( 0x5, 7 ), /* str=0000101 */
- MKVLC( 0x3, 5 ), /* str=00011 */
-
- MKVLC( 0x7, 10 ), /* str=0000000111 */
- MKVLC( 0x6, 9 ), /* str=000000110 */
- MKVLC( 0x5, 8 ), /* str=00000101 */
- MKVLC( 0x3, 6 ), /* str=000011 */
-
- MKVLC( 0x7, 11 ), /* str=00000000111 */
- MKVLC( 0x6, 10 ), /* str=0000000110 */
- MKVLC( 0x5, 9 ), /* str=000000101 */
- MKVLC( 0x4, 7 ), /* str=0000100 */
-
- MKVLC( 0xf, 13 ), /* str=0000000001111 */
- MKVLC( 0x6, 11 ), /* str=00000000110 */
- MKVLC( 0x5, 10 ), /* str=0000000101 */
- MKVLC( 0x4, 8 ), /* str=00000100 */
-
- MKVLC( 0xb, 13 ), /* str=0000000001011 */
- MKVLC( 0xe, 13 ), /* str=0000000001110 */
- MKVLC( 0x5, 11 ), /* str=00000000101 */
- MKVLC( 0x4, 9 ), /* str=000000100 */
-
- MKVLC( 0x8, 13 ), /* str=0000000001000 */
- MKVLC( 0xa, 13 ), /* str=0000000001010 */
- MKVLC( 0xd, 13 ), /* str=0000000001101 */
- MKVLC( 0x4, 10 ), /* str=0000000100 */
-
- MKVLC( 0xf, 14 ), /* str=00000000001111 */
- MKVLC( 0xe, 14 ), /* str=00000000001110 */
- MKVLC( 0x9, 13 ), /* str=0000000001001 */
- MKVLC( 0x4, 11 ), /* str=00000000100 */
-
- MKVLC( 0xb, 14 ), /* str=00000000001011 */
- MKVLC( 0xa, 14 ), /* str=00000000001010 */
- MKVLC( 0xd, 14 ), /* str=00000000001101 */
- MKVLC( 0xc, 13 ), /* str=0000000001100 */
-
- MKVLC( 0xf, 15 ), /* str=000000000001111 */
- MKVLC( 0xe, 15 ), /* str=000000000001110 */
- MKVLC( 0x9, 14 ), /* str=00000000001001 */
- MKVLC( 0xc, 14 ), /* str=00000000001100 */
-
- MKVLC( 0xb, 15 ), /* str=000000000001011 */
- MKVLC( 0xa, 15 ), /* str=000000000001010 */
- MKVLC( 0xd, 15 ), /* str=000000000001101 */
- MKVLC( 0x8, 14 ), /* str=00000000001000 */
-
- MKVLC( 0xf, 16 ), /* str=0000000000001111 */
- MKVLC( 0x1, 15 ), /* str=000000000000001 */
- MKVLC( 0x9, 15 ), /* str=000000000001001 */
- MKVLC( 0xc, 15 ), /* str=000000000001100 */
-
- MKVLC( 0xb, 16 ), /* str=0000000000001011 */
- MKVLC( 0xe, 16 ), /* str=0000000000001110 */
- MKVLC( 0xd, 16 ), /* str=0000000000001101 */
- MKVLC( 0x8, 15 ), /* str=000000000001000 */
-
- MKVLC( 0x7, 16 ), /* str=0000000000000111 */
- MKVLC( 0xa, 16 ), /* str=0000000000001010 */
- MKVLC( 0x9, 16 ), /* str=0000000000001001 */
- MKVLC( 0xc, 16 ), /* str=0000000000001100 */
-
- MKVLC( 0x4, 16 ), /* str=0000000000000100 */
- MKVLC( 0x6, 16 ), /* str=0000000000000110 */
- MKVLC( 0x5, 16 ), /* str=0000000000000101 */
- MKVLC( 0x8, 16 ), /* str=0000000000001000 */
- },
-
- /* table 1 */
- {
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0xb, 6 ), /* str=001011 */
- MKVLC( 0x2, 2 ), /* str=10 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x7, 6 ), /* str=000111 */
- MKVLC( 0x7, 5 ), /* str=00111 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x7, 7 ), /* str=0000111 */
- MKVLC( 0xa, 6 ), /* str=001010 */
- MKVLC( 0x9, 6 ), /* str=001001 */
- MKVLC( 0x5, 4 ), /* str=0101 */
-
- MKVLC( 0x7, 8 ), /* str=00000111 */
- MKVLC( 0x6, 6 ), /* str=000110 */
- MKVLC( 0x5, 6 ), /* str=000101 */
- MKVLC( 0x4, 4 ), /* str=0100 */
-
- MKVLC( 0x4, 8 ), /* str=00000100 */
- MKVLC( 0x6, 7 ), /* str=0000110 */
- MKVLC( 0x5, 7 ), /* str=0000101 */
- MKVLC( 0x6, 5 ), /* str=00110 */
-
- MKVLC( 0x7, 9 ), /* str=000000111 */
- MKVLC( 0x6, 8 ), /* str=00000110 */
- MKVLC( 0x5, 8 ), /* str=00000101 */
- MKVLC( 0x8, 6 ), /* str=001000 */
-
- MKVLC( 0xf, 11 ), /* str=00000001111 */
- MKVLC( 0x6, 9 ), /* str=000000110 */
- MKVLC( 0x5, 9 ), /* str=000000101 */
- MKVLC( 0x4, 6 ), /* str=000100 */
-
- MKVLC( 0xb, 11 ), /* str=00000001011 */
- MKVLC( 0xe, 11 ), /* str=00000001110 */
- MKVLC( 0xd, 11 ), /* str=00000001101 */
- MKVLC( 0x4, 7 ), /* str=0000100 */
-
- MKVLC( 0xf, 12 ), /* str=000000001111 */
- MKVLC( 0xa, 11 ), /* str=00000001010 */
- MKVLC( 0x9, 11 ), /* str=00000001001 */
- MKVLC( 0x4, 9 ), /* str=000000100 */
-
- MKVLC( 0xb, 12 ), /* str=000000001011 */
- MKVLC( 0xe, 12 ), /* str=000000001110 */
- MKVLC( 0xd, 12 ), /* str=000000001101 */
- MKVLC( 0xc, 11 ), /* str=00000001100 */
-
- MKVLC( 0x8, 12 ), /* str=000000001000 */
- MKVLC( 0xa, 12 ), /* str=000000001010 */
- MKVLC( 0x9, 12 ), /* str=000000001001 */
- MKVLC( 0x8, 11 ), /* str=00000001000 */
-
- MKVLC( 0xf, 13 ), /* str=0000000001111 */
- MKVLC( 0xe, 13 ), /* str=0000000001110 */
- MKVLC( 0xd, 13 ), /* str=0000000001101 */
- MKVLC( 0xc, 12 ), /* str=000000001100 */
-
- MKVLC( 0xb, 13 ), /* str=0000000001011 */
- MKVLC( 0xa, 13 ), /* str=0000000001010 */
- MKVLC( 0x9, 13 ), /* str=0000000001001 */
- MKVLC( 0xc, 13 ), /* str=0000000001100 */
-
- MKVLC( 0x7, 13 ), /* str=0000000000111 */
- MKVLC( 0xb, 14 ), /* str=00000000001011 */
- MKVLC( 0x6, 13 ), /* str=0000000000110 */
- MKVLC( 0x8, 13 ), /* str=0000000001000 */
-
- MKVLC( 0x9, 14 ), /* str=00000000001001 */
- MKVLC( 0x8, 14 ), /* str=00000000001000 */
- MKVLC( 0xa, 14 ), /* str=00000000001010 */
- MKVLC( 0x1, 13 ), /* str=0000000000001 */
-
- MKVLC( 0x7, 14 ), /* str=00000000000111 */
- MKVLC( 0x6, 14 ), /* str=00000000000110 */
- MKVLC( 0x5, 14 ), /* str=00000000000101 */
- MKVLC( 0x4, 14 ), /* str=00000000000100 */
- },
- /* table 2 */
- {
- MKVLC( 0xf, 4 ), /* str=1111 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0xf, 6 ), /* str=001111 */
- MKVLC( 0xe, 4 ), /* str=1110 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0xb, 6 ), /* str=001011 */
- MKVLC( 0xf, 5 ), /* str=01111 */
- MKVLC( 0xd, 4 ), /* str=1101 */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x8, 6 ), /* str=001000 */
- MKVLC( 0xc, 5 ), /* str=01100 */
- MKVLC( 0xe, 5 ), /* str=01110 */
- MKVLC( 0xc, 4 ), /* str=1100 */
-
- MKVLC( 0xf, 7 ), /* str=0001111 */
- MKVLC( 0xa, 5 ), /* str=01010 */
- MKVLC( 0xb, 5 ), /* str=01011 */
- MKVLC( 0xb, 4 ), /* str=1011 */
-
- MKVLC( 0xb, 7 ), /* str=0001011 */
- MKVLC( 0x8, 5 ), /* str=01000 */
- MKVLC( 0x9, 5 ), /* str=01001 */
- MKVLC( 0xa, 4 ), /* str=1010 */
-
- MKVLC( 0x9, 7 ), /* str=0001001 */
- MKVLC( 0xe, 6 ), /* str=001110 */
- MKVLC( 0xd, 6 ), /* str=001101 */
- MKVLC( 0x9, 4 ), /* str=1001 */
-
- MKVLC( 0x8, 7 ), /* str=0001000 */
- MKVLC( 0xa, 6 ), /* str=001010 */
- MKVLC( 0x9, 6 ), /* str=001001 */
- MKVLC( 0x8, 4 ), /* str=1000 */
-
- MKVLC( 0xf, 8 ), /* str=00001111 */
- MKVLC( 0xe, 7 ), /* str=0001110 */
- MKVLC( 0xd, 7 ), /* str=0001101 */
- MKVLC( 0xd, 5 ), /* str=01101 */
-
- MKVLC( 0xb, 8 ), /* str=00001011 */
- MKVLC( 0xe, 8 ), /* str=00001110 */
- MKVLC( 0xa, 7 ), /* str=0001010 */
- MKVLC( 0xc, 6 ), /* str=001100 */
-
- MKVLC( 0xf, 9 ), /* str=000001111 */
- MKVLC( 0xa, 8 ), /* str=00001010 */
- MKVLC( 0xd, 8 ), /* str=00001101 */
- MKVLC( 0xc, 7 ), /* str=0001100 */
-
- MKVLC( 0xb, 9 ), /* str=000001011 */
- MKVLC( 0xe, 9 ), /* str=000001110 */
- MKVLC( 0x9, 8 ), /* str=00001001 */
- MKVLC( 0xc, 8 ), /* str=00001100 */
-
- MKVLC( 0x8, 9 ), /* str=000001000 */
- MKVLC( 0xa, 9 ), /* str=000001010 */
- MKVLC( 0xd, 9 ), /* str=000001101 */
- MKVLC( 0x8, 8 ), /* str=00001000 */
-
- MKVLC( 0xd, 10 ), /* str=0000001101 */
- MKVLC( 0x7, 9 ), /* str=000000111 */
- MKVLC( 0x9, 9 ), /* str=000001001 */
- MKVLC( 0xc, 9 ), /* str=000001100 */
-
- MKVLC( 0x9, 10 ), /* str=0000001001 */
- MKVLC( 0xc, 10 ), /* str=0000001100 */
- MKVLC( 0xb, 10 ), /* str=0000001011 */
- MKVLC( 0xa, 10 ), /* str=0000001010 */
-
- MKVLC( 0x5, 10 ), /* str=0000000101 */
- MKVLC( 0x8, 10 ), /* str=0000001000 */
- MKVLC( 0x7, 10 ), /* str=0000000111 */
- MKVLC( 0x6, 10 ), /* str=0000000110 */
-
- MKVLC( 0x1, 10 ), /* str=0000000001 */
- MKVLC( 0x4, 10 ), /* str=0000000100 */
- MKVLC( 0x3, 10 ), /* str=0000000011 */
- MKVLC( 0x2, 10 ), /* str=0000000010 */
- },
-
- /* table 3 */
- {
- MKVLC( 0x3, 6 ), /* str=000011 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 6 ), /* str=000000 */
- MKVLC( 0x1, 6 ), /* str=000001 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x4, 6 ), /* str=000100 */
- MKVLC( 0x5, 6 ), /* str=000101 */
- MKVLC( 0x6, 6 ), /* str=000110 */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x8, 6 ), /* str=001000 */
- MKVLC( 0x9, 6 ), /* str=001001 */
- MKVLC( 0xa, 6 ), /* str=001010 */
- MKVLC( 0xb, 6 ), /* str=001011 */
-
- MKVLC( 0xc, 6 ), /* str=001100 */
- MKVLC( 0xd, 6 ), /* str=001101 */
- MKVLC( 0xe, 6 ), /* str=001110 */
- MKVLC( 0xf, 6 ), /* str=001111 */
-
- MKVLC( 0x10, 6 ), /* str=010000 */
- MKVLC( 0x11, 6 ), /* str=010001 */
- MKVLC( 0x12, 6 ), /* str=010010 */
- MKVLC( 0x13, 6 ), /* str=010011 */
-
- MKVLC( 0x14, 6 ), /* str=010100 */
- MKVLC( 0x15, 6 ), /* str=010101 */
- MKVLC( 0x16, 6 ), /* str=010110 */
- MKVLC( 0x17, 6 ), /* str=010111 */
-
- MKVLC( 0x18, 6 ), /* str=011000 */
- MKVLC( 0x19, 6 ), /* str=011001 */
- MKVLC( 0x1a, 6 ), /* str=011010 */
- MKVLC( 0x1b, 6 ), /* str=011011 */
-
- MKVLC( 0x1c, 6 ), /* str=011100 */
- MKVLC( 0x1d, 6 ), /* str=011101 */
- MKVLC( 0x1e, 6 ), /* str=011110 */
- MKVLC( 0x1f, 6 ), /* str=011111 */
-
- MKVLC( 0x20, 6 ), /* str=100000 */
- MKVLC( 0x21, 6 ), /* str=100001 */
- MKVLC( 0x22, 6 ), /* str=100010 */
- MKVLC( 0x23, 6 ), /* str=100011 */
-
- MKVLC( 0x24, 6 ), /* str=100100 */
- MKVLC( 0x25, 6 ), /* str=100101 */
- MKVLC( 0x26, 6 ), /* str=100110 */
- MKVLC( 0x27, 6 ), /* str=100111 */
-
- MKVLC( 0x28, 6 ), /* str=101000 */
- MKVLC( 0x29, 6 ), /* str=101001 */
- MKVLC( 0x2a, 6 ), /* str=101010 */
- MKVLC( 0x2b, 6 ), /* str=101011 */
-
- MKVLC( 0x2c, 6 ), /* str=101100 */
- MKVLC( 0x2d, 6 ), /* str=101101 */
- MKVLC( 0x2e, 6 ), /* str=101110 */
- MKVLC( 0x2f, 6 ), /* str=101111 */
-
- MKVLC( 0x30, 6 ), /* str=110000 */
- MKVLC( 0x31, 6 ), /* str=110001 */
- MKVLC( 0x32, 6 ), /* str=110010 */
- MKVLC( 0x33, 6 ), /* str=110011 */
-
- MKVLC( 0x34, 6 ), /* str=110100 */
- MKVLC( 0x35, 6 ), /* str=110101 */
- MKVLC( 0x36, 6 ), /* str=110110 */
- MKVLC( 0x37, 6 ), /* str=110111 */
-
- MKVLC( 0x38, 6 ), /* str=111000 */
- MKVLC( 0x39, 6 ), /* str=111001 */
- MKVLC( 0x3a, 6 ), /* str=111010 */
- MKVLC( 0x3b, 6 ), /* str=111011 */
-
- MKVLC( 0x3c, 6 ), /* str=111100 */
- MKVLC( 0x3d, 6 ), /* str=111101 */
- MKVLC( 0x3e, 6 ), /* str=111110 */
- MKVLC( 0x3f, 6 ), /* str=111111 */
- },
-
- /* table 4 */
- {
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x7, 6 ), /* str=000111 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x4, 6 ), /* str=000100 */
- MKVLC( 0x6, 6 ), /* str=000110 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x3, 6 ), /* str=000011 */
- MKVLC( 0x3, 7 ), /* str=0000011 */
- MKVLC( 0x2, 7 ), /* str=0000010 */
- MKVLC( 0x5, 6 ), /* str=000101 */
-
- MKVLC( 0x2, 6 ), /* str=000010 */
- MKVLC( 0x3, 8 ), /* str=00000011 */
- MKVLC( 0x2, 8 ), /* str=00000010 */
- MKVLC( 0x0, 7 ), /* str=0000000 */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
-
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- }
-};
-
-static const vlc_t x264_level_prefix[16] =
-{
- MKVLC( 0x01, 1 ),
- MKVLC( 0x01, 2 ),
- MKVLC( 0x01, 3 ),
- MKVLC( 0x01, 4 ),
- MKVLC( 0x01, 5 ),
- MKVLC( 0x01, 6 ),
- MKVLC( 0x01, 7 ),
- MKVLC( 0x01, 8 ),
- MKVLC( 0x01, 9 ),
- MKVLC( 0x01, 10 ),
- MKVLC( 0x01, 11 ),
- MKVLC( 0x01, 12 ),
- MKVLC( 0x01, 13 ),
- MKVLC( 0x01, 14 ),
- MKVLC( 0x01, 15 ),
- MKVLC( 0x01, 16 )
-};
-
-/* [i_total_coeff-1][i_total_zeros] */
-static const vlc_t x264_total_zeros[15][16] =
-{
- { /* i_total 1 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x2, 3 ), /* str=010 */
- MKVLC( 0x3, 4 ), /* str=0011 */
- MKVLC( 0x2, 4 ), /* str=0010 */
- MKVLC( 0x3, 5 ), /* str=00011 */
- MKVLC( 0x2, 5 ), /* str=00010 */
- MKVLC( 0x3, 6 ), /* str=000011 */
- MKVLC( 0x2, 6 ), /* str=000010 */
- MKVLC( 0x3, 7 ), /* str=0000011 */
- MKVLC( 0x2, 7 ), /* str=0000010 */
- MKVLC( 0x3, 8 ), /* str=00000011 */
- MKVLC( 0x2, 8 ), /* str=00000010 */
- MKVLC( 0x3, 9 ), /* str=000000011 */
- MKVLC( 0x2, 9 ), /* str=000000010 */
- MKVLC( 0x1, 9 ), /* str=000000001 */
- },
- { /* i_total 2 */
- MKVLC( 0x7, 3 ), /* str=111 */
- MKVLC( 0x6, 3 ), /* str=110 */
- MKVLC( 0x5, 3 ), /* str=101 */
- MKVLC( 0x4, 3 ), /* str=100 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x5, 4 ), /* str=0101 */
- MKVLC( 0x4, 4 ), /* str=0100 */
- MKVLC( 0x3, 4 ), /* str=0011 */
- MKVLC( 0x2, 4 ), /* str=0010 */
- MKVLC( 0x3, 5 ), /* str=00011 */
- MKVLC( 0x2, 5 ), /* str=00010 */
- MKVLC( 0x3, 6 ), /* str=000011 */
- MKVLC( 0x2, 6 ), /* str=000010 */
- MKVLC( 0x1, 6 ), /* str=000001 */
- MKVLC( 0x0, 6 ), /* str=000000 */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 3 */
- MKVLC( 0x5, 4 ), /* str=0101 */
- MKVLC( 0x7, 3 ), /* str=111 */
- MKVLC( 0x6, 3 ), /* str=110 */
- MKVLC( 0x5, 3 ), /* str=101 */
- MKVLC( 0x4, 4 ), /* str=0100 */
- MKVLC( 0x3, 4 ), /* str=0011 */
- MKVLC( 0x4, 3 ), /* str=100 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x2, 4 ), /* str=0010 */
- MKVLC( 0x3, 5 ), /* str=00011 */
- MKVLC( 0x2, 5 ), /* str=00010 */
- MKVLC( 0x1, 6 ), /* str=000001 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x0, 6 ), /* str=000000 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 4 */
- MKVLC( 0x3, 5 ), /* str=00011 */
- MKVLC( 0x7, 3 ), /* str=111 */
- MKVLC( 0x5, 4 ), /* str=0101 */
- MKVLC( 0x4, 4 ), /* str=0100 */
- MKVLC( 0x6, 3 ), /* str=110 */
- MKVLC( 0x5, 3 ), /* str=101 */
- MKVLC( 0x4, 3 ), /* str=100 */
- MKVLC( 0x3, 4 ), /* str=0011 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x2, 4 ), /* str=0010 */
- MKVLC( 0x2, 5 ), /* str=00010 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x0, 5 ), /* str=00000 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 5 */
- MKVLC( 0x5, 4 ), /* str=0101 */
- MKVLC( 0x4, 4 ), /* str=0100 */
- MKVLC( 0x3, 4 ), /* str=0011 */
- MKVLC( 0x7, 3 ), /* str=111 */
- MKVLC( 0x6, 3 ), /* str=110 */
- MKVLC( 0x5, 3 ), /* str=101 */
- MKVLC( 0x4, 3 ), /* str=100 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x2, 4 ), /* str=0010 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x0, 5 ), /* str=00000 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 6 */
- MKVLC( 0x1, 6 ), /* str=000001 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x7, 3 ), /* str=111 */
- MKVLC( 0x6, 3 ), /* str=110 */
- MKVLC( 0x5, 3 ), /* str=101 */
- MKVLC( 0x4, 3 ), /* str=100 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x2, 3 ), /* str=010 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x0, 6 ), /* str=000000 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 7 */
- MKVLC( 0x1, 6 ), /* str=000001 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x5, 3 ), /* str=101 */
- MKVLC( 0x4, 3 ), /* str=100 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x2, 3 ), /* str=010 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x0, 6 ), /* str=000000 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 8 */
- MKVLC( 0x1, 6 ), /* str=000001 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x2, 2 ), /* str=10 */
- MKVLC( 0x2, 3 ), /* str=010 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x0, 6 ), /* str=000000 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 9 */
- MKVLC( 0x1, 6 ), /* str=000001 */
- MKVLC( 0x0, 6 ), /* str=000000 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x2, 2 ), /* str=10 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 10 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x0, 5 ), /* str=00000 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x2, 2 ), /* str=10 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 11 */
- MKVLC( 0x0, 4 ), /* str=0000 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x2, 3 ), /* str=010 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 12 */
- MKVLC( 0x0, 4 ), /* str=0000 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 13 */
- MKVLC( 0x0, 3 ), /* str=000 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 14 */
- MKVLC( 0x0, 2 ), /* str=00 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_total 15 */
- MKVLC( 0x0, 1 ), /* str=0 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
-};
-
-/* [i_total_coeff-1][i_total_zeros] */
-static const vlc_t x264_total_zeros_dc[3][4] =
-{
- {
- MKVLC( 0x01, 1 ), /* 1 */
- MKVLC( 0x01, 2 ), /* 01 */
- MKVLC( 0x01, 3 ), /* 001*/
- MKVLC( 0x00, 3 ) /* 000*/
- },
- {
- MKVLC( 0x01, 1 ), /* 1 */
- MKVLC( 0x01, 2 ), /* 01 */
- MKVLC( 0x00, 2 ), /* 00 */
- MKVLC( 0x00, 0 ) /* */
- },
- {
- MKVLC( 0x01, 1 ), /* 1 */
- MKVLC( 0x00, 1 ), /* 0 */
- MKVLC( 0x00, 0 ), /* */
- MKVLC( 0x00, 0 ) /* */
- }
-};
-
-/* x264_run_before[__MIN( i_zero_left -1, 6 )][run_before] */
-static const vlc_t x264_run_before[7][15] =
-{
- { /* i_zero_left 1 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x0, 1 ), /* str=0 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_zero_left 2 */
- MKVLC( 0x1, 1 ), /* str=1 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x0, 2 ), /* str=00 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_zero_left 3 */
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x2, 2 ), /* str=10 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x0, 2 ), /* str=00 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_zero_left 4 */
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x2, 2 ), /* str=10 */
- MKVLC( 0x1, 2 ), /* str=01 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x0, 3 ), /* str=000 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_zero_left 5 */
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x2, 2 ), /* str=10 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x2, 3 ), /* str=010 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x0, 3 ), /* str=000 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_zero_left 6 */
- MKVLC( 0x3, 2 ), /* str=11 */
- MKVLC( 0x0, 3 ), /* str=000 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x2, 3 ), /* str=010 */
- MKVLC( 0x5, 3 ), /* str=101 */
- MKVLC( 0x4, 3 ), /* str=100 */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- MKVLC( 0x0, 0 ), /* str= */
- },
- { /* i_zero_left 7 */
- MKVLC( 0x7, 3 ), /* str=111 */
- MKVLC( 0x6, 3 ), /* str=110 */
- MKVLC( 0x5, 3 ), /* str=101 */
- MKVLC( 0x4, 3 ), /* str=100 */
- MKVLC( 0x3, 3 ), /* str=011 */
- MKVLC( 0x2, 3 ), /* str=010 */
- MKVLC( 0x1, 3 ), /* str=001 */
- MKVLC( 0x1, 4 ), /* str=0001 */
- MKVLC( 0x1, 5 ), /* str=00001 */
- MKVLC( 0x1, 6 ), /* str=000001 */
- MKVLC( 0x1, 7 ), /* str=0000001 */
- MKVLC( 0x1, 8 ), /* str=00000001 */
- MKVLC( 0x1, 9 ), /* str=000000001 */
- MKVLC( 0x1, 10 ), /* str=0000000001 */
- MKVLC( 0x1, 11 ), /* str=00000000001 */
- },
-};
#include <string.h>
#include <stdint.h>
-#include "../core/common.h"
-#include "../core/cpu.h"
-#include "../core/vlc.h"
+#include "../common/common.h"
+#include "../common/cpu.h"
+#include "../common/vlc.h"
#include "macroblock.h"
#include "set.h"
#include <string.h>
#include <stdint.h>
-#include "../core/common.h"
-#include "../core/vlc.h"
+#include "../common/common.h"
+#include "../common/vlc.h"
#include "vlc.h"
#include "macroblock.h"
#include <string.h>
#include <stdint.h>
-#include "../core/common.h"
+#include "../common/common.h"
#include "set.h"
/* return -1 if invalid, else the id */
#include <stdio.h>
#include <inttypes.h>
-#include "../core/common.h"
-#include "../core/vlc.h"
+#include "../common/common.h"
+#include "../common/vlc.h"
#include "vlc.h"
#include <math.h>
#include <limits.h>
-#include "../core/common.h"
-#include "../core/macroblock.h"
+#include "../common/common.h"
+#include "../common/macroblock.h"
#include "macroblock.h"
#include "me.h"
#include "ratecontrol.h"
#include <stdio.h>
#include <string.h>
-#include "../core/common.h"
+#include "../common/common.h"
#include "macroblock.h"
static const uint8_t block_idx_x[16] =
#include <stdio.h>
#include <string.h>
-#include "../core/common.h"
-#include "../core/vlc.h"
+#include "../common/common.h"
+#include "../common/vlc.h"
#include "macroblock.h"
static const uint8_t intra4x4_cbp_to_golomb[48]=
#include <math.h>
-#include "../core/common.h"
-#include "../core/cpu.h"
+#include "../common/common.h"
+#include "../common/cpu.h"
#include "set.h"
#include "analyse.h"
#include <stdio.h>
#include <string.h>
-#include "../core/common.h"
+#include "../common/common.h"
#include "macroblock.h"
#ifndef _ENCODER_MACROBLOCK_H
#define _ENCODER_MACROBLOCK_H 1
-#include "../core/macroblock.h"
+#include "../common/macroblock.h"
int x264_macroblock_probe_pskip( x264_t *h );
#include <stdio.h>
#include <string.h>
-#include "../core/common.h"
+#include "../common/common.h"
#include "me.h"
/* presets selected from good points on the speed-vs-quality curve of several test videos
#include <limits.h>
#include <assert.h>
-#include "../core/common.h"
-#include "../core/cpu.h"
-#include "../core/macroblock.h"
+#include "../common/common.h"
+#include "../common/cpu.h"
+#include "../common/macroblock.h"
#include "ratecontrol.h"
#ifdef SYS_MACOSX
#include <stdarg.h>
#include "../x264.h"
-#include "../core/bs.h"
-#include "../core/set.h"
+#include "../common/bs.h"
+#include "../common/set.h"
void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
{
#include <string.h>
#
-#include "core/common.h"
+#include "common/common.h"
#ifdef HAVE_MMXEXT
-#include "core/i386/pixel.h"
-#include "core/i386/dct.h"
-#include "core/i386/mc.h"
+#include "common/i386/pixel.h"
+#include "common/i386/dct.h"
+#include "common/i386/mc.h"
#endif
#ifdef ARCH_PPC
-#include "core/ppc/pixel.h"
+#include "common/ppc/pixel.h"
#endif
/* buf1, buf2: initialised to randome data and shouldn't write into them */
#include <string.h>
#include <stdint.h>
-#include "../core/common.h"
-#include "../core/vlc.h"
+#include "../common/common.h"
+#include "../common/vlc.h"
#include "macroblock.h"
static const uint8_t intra4x4_cbp_to_golomb[48]=
#include <fcntl.h> /* _O_BINARY */
#endif
-#include "../core/bs.h"
+#include "../common/bs.h"
#define DATA_MAX 3000000
uint8_t data[DATA_MAX];
#include <fcntl.h> /* _O_BINARY */
#endif
-#include "core/common.h"
+#include "common/common.h"
#include "x264.h"
#define DATA_MAX 3000000