* postprocessing_c.c: Post Processing plugin in C
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: postprocessing_c.c,v 1.1 2002/08/04 22:13:06 fenrir Exp $
+ * $Id: postprocessing_c.c,v 1.2 2002/12/06 16:34:05 sam 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-#include <vlc/vlc.h> /* only use u8, u32 .... */
+#include <vlc/vlc.h> /* only use uint8_t, uint32_t .... */
#include "postprocessing.h"
#include "postprocessing_common.h"
* so need to be fast ...
*
****************************************************************************/
-static inline int pp_deblock_isDC_mode( u8 *p_v )
+static inline int pp_deblock_isDC_mode( uint8_t *p_v )
{
- int i_eq_cnt;
+ unsigned int i_eq_cnt;
/* algo : if ( | v[i] -v[i+1] | <= PP_THR1 ) { i_eq_cnt++; } */
i_eq_cnt = 0;
int i;
for( i =0; i < 9; i++ )
{
- if(( ( p_v[i] - p_v[i+1] + PP_THR1 )&0xffff )<= PP_2xTHR1 )
- {
+ if(( ( p_v[i] - p_v[i+1] + PP_THR1 )&0xffff )<= PP_2xTHR1 )
+ {
i_eq_cnt++;
}
}
return( (i_eq_cnt >= PP_THR2 ) ? 1 : 0 );
}
-static inline int pp_deblock_isMinMaxOk( u8 *p_v, int i_QP )
+static inline int pp_deblock_isMinMaxOk( uint8_t *p_v, int i_QP )
{
int i_max, i_min;
- i_min = i_max = p_v[1];
+ i_min = i_max = p_v[1];
if( i_max < p_v[1] ) i_max = p_v[1];
if( i_min > p_v[1] ) i_min = p_v[1];
if( i_max < p_v[2] ) i_max = p_v[2];
}
-static inline void pp_deblock_DefaultMode( u8 i_v[10], int i_stride,
+static inline void pp_deblock_DefaultMode( uint8_t i_v[10], int i_stride,
int i_QP )
{
int d, i_delta;
{
b_neg = 1;
a3x0 = -a3x0;
- }
+ }
else
{
b_neg = 0;
if( a3x2 < 0) a3x2 = -a3x2; /* abs( a3x2 ) */
a3x0_ = PP_MIN3( a3x0, a3x1, a3x2 );
-
+
d = 5 *( a3x0 - a3x0_ ) / 8; /* always > 0 */
i_delta = ( i_v[4] - i_v[5] ) / 2;
-static inline void pp_deblock_DCMode( u8 *p_v, /* = int i_v[10] */
+static inline void pp_deblock_DCMode( uint8_t *p_v, /* = int i_v[10] */
int i_QP )
{
int v[10];
int i;
-
+
int i_p0, i_p9;
i_p0 = PP_ABS( p_v[1] - p_v[0] ) < i_QP ? p_v[0] : p_v[1];
i_p9 = PP_ABS( p_v[8] - p_v[9] ) < i_QP ? p_v[9] : p_v[8];
v[i] = p_v[i]; /* save 8 pix that will be modified */
}
- p_v[1] = ( 6 * i_p0 + 4 * v[1]
+ p_v[1] = ( 6 * i_p0 + 4 * v[1]
+ 2 *( v[2] + v[3]) + v[4] + v[5]) >> 4;
-
- p_v[2] = ( 4 * i_p0 + 2 * v[1] + 4 * v[2]
+
+ p_v[2] = ( 4 * i_p0 + 2 * v[1] + 4 * v[2]
+ 2 *( v[3] + v[4]) + v[5] + v[6]) >> 4;
- p_v[3] = ( 2 * i_p0 + 2 * (v[1] + v[2]) + 4 * v[3]
+ p_v[3] = ( 2 * i_p0 + 2 * (v[1] + v[2]) + 4 * v[3]
+ 2 *( v[4] + v[5]) + v[6] + v[7]) >> 4;
- p_v[4] = ( i_p0 + v[1] + 2 * (v[2] + v[3]) + 4 * v[4]
+ p_v[4] = ( i_p0 + v[1] + 2 * (v[2] + v[3]) + 4 * v[4]
+ 2 *( v[5] + v[6]) + v[7] + v[8]) >> 4;
- p_v[5] = ( v[1] + v[2] + 2 * (v[3] + v[4]) + 4 * v[5]
+ p_v[5] = ( v[1] + v[2] + 2 * (v[3] + v[4]) + 4 * v[5]
+ 2 *( v[6] + v[7]) + v[8] + i_p9) >> 4;
- p_v[6] = ( v[2] + v[3] + 2 * (v[4] + v[5]) + 4 * v[6]
+ p_v[6] = ( v[2] + v[3] + 2 * (v[4] + v[5]) + 4 * v[6]
+ 2 *( v[7] + v[8]) + 2 * i_p9) >> 4;
- p_v[7] = ( v[3] + v[4] + 2 * (v[5] + v[6]) + 4 * v[7]
+ p_v[7] = ( v[3] + v[4] + 2 * (v[5] + v[6]) + 4 * v[7]
+ 2 * v[8] + 4 * i_p9) >> 4;
- p_v[8] = ( v[4] + v[5] + 2 * (v[6] + v[7]) + 4 * v[8]
+ p_v[8] = ( v[4] + v[5] + 2 * (v[6] + v[7]) + 4 * v[8]
+ 6 * i_p9) >> 4;
}
/*---------------------------------------------------------------------------*/
/*****************************************************************************/
-void E_( pp_deblock_V )( u8 *p_plane,
+void E_( pp_deblock_V )( uint8_t *p_plane,
int i_width, int i_height, int i_stride,
QT_STORE_T *p_QP_store, int i_QP_stride,
int b_chroma )
{
int x, y, i;
- u8 *p_v;
+ uint8_t *p_v;
int i_QP_scale; /* use to do ( ? >> i_QP_scale ) */
int i_QP;
-
- u8 i_v[10];
-
+
+ uint8_t i_v[10];
+
i_QP_scale = b_chroma ? 5 : 4 ;
- for( y = 8; y < i_height - 4; y += 8 )
+ for( y = 8; y < i_height - 4; y += 8 )
{
p_v = p_plane + ( y - 5 )* i_stride;
for( x = 0; x < i_width; x++ )
/*---------------------------------------------------------------------------*/
/*****************************************************************************/
-void E_( pp_deblock_H )( u8 *p_plane,
+void E_( pp_deblock_H )( uint8_t *p_plane,
int i_width, int i_height, int i_stride,
QT_STORE_T *p_QP_store, int i_QP_stride,
int b_chroma )
{
int x, y;
- u8 *p_v;
+ uint8_t *p_v;
int i_QP_scale;
int i_QP;
-
+
i_QP_scale = b_chroma ? 5 : 4 ;
- for( y = 0; y < i_height; y++ )
+ for( y = 0; y < i_height; y++ )
{
p_v = p_plane + y * i_stride - 5;
- for( x = 8; x < i_width - 4; x += 8 )
+ for( x = 8; x < i_width - 4; x += 8 )
{
/* p_v point 5 pix before a block boundary */
/* XXX QP is for v5 */
}
}
}
-
+
return;
}
*
*****************************************************************************/
-static inline void pp_dering_MinMax( u8 *p_block, int i_stride,
+static inline void pp_dering_MinMax( uint8_t *p_block, int i_stride,
int *pi_min, int *pi_max )
{
int y;
int i_min, i_max;
i_min = 255; i_max = 0;
-
+
for( y = 0; y < 8; y++ )
{
if( i_min > p_block[0] ) i_min = p_block[0];
#endif
p_block += i_stride;
}
-
+
*pi_min = i_min;
*pi_max = i_max;
}
-static inline void pp_dering_BinIndex( u8 *p_block, int i_stride, int i_thr,
- u32 *p_bin )
+static inline void pp_dering_BinIndex( uint8_t *p_block, int i_stride,
+ int i_thr, uint32_t *p_bin )
{
int x, y;
- u32 i_bin;
+ uint32_t i_bin;
for( y = 0; y < 10; y++ )
{
}
}
-static inline void pp_dering_Filter( u8 *p_block, int i_stride,
- u32 *p_bin,
+static inline void pp_dering_Filter( uint8_t *p_block, int i_stride,
+ uint32_t *p_bin,
int i_QP )
{
int x, y;
- u32 i_bin;
+ uint32_t i_bin;
int i_flt[8][8];
int i_f;
- u8 *p_sav;
+ uint8_t *p_sav;
int i_QP_2;
-
+
p_sav = p_block;
i_QP_2 = i_QP >> 1;
-
+
for( y = 0; y < 8; y++ )
{
i_bin = p_bin[y] & p_bin[y+1] & p_bin[y+2]; /* To be optimised */
i_bin |= i_bin >> 16; /* detect 0 or 1 */
for( x = 0; x < 8; x++ )
- {
+ {
if( i_bin&0x02 ) /* 0x02 since 10 index but want 1-9 */
{
/* apply dering */
i_f = p_block[x - i_stride - 1] +
( p_block[x - i_stride ] << 1)+
p_block[x - i_stride + 1] +
-
+
( p_block[x - 1] << 1 )+
( p_block[x ] << 2 )+
( p_block[x + 1] << 1 )+
-
+
p_block[x + i_stride - 1] +
( p_block[x + i_stride ] << 1 ) +
p_block[x + i_stride + 1];
}
else
{
- i_flt[y][x] = i_f ;
+ i_flt[y][x] = i_f ;
}
}
else
i_flt[y][x] = p_block[x];
}
i_bin >>= 1;
-
+
}
p_block += i_stride;
}
/*---------------------------------------------------------------------------*/
/*****************************************************************************/
-void E_( pp_dering_Y )( u8 *p_plane,
+void E_( pp_dering_Y )( uint8_t *p_plane,
int i_width, int i_height, int i_stride,
QT_STORE_T *p_QP_store, int i_QP_stride )
{
int i_max[4], i_min[4], i_range[4];
int i_thr[4];
int i_max_range, i_kmax;
- u32 i_bin[4][10];
- u8 *p_block[4];
+ uint32_t i_bin[4][10];
+ uint8_t *p_block[4];
QT_STORE_T *p_QP;
-
+
/* We process 4 blocks/loop*/
for( y = 8; y < i_height-8; y += 16 )
{
i_thr[2], i_bin[2] );
pp_dering_BinIndex( p_block[3] - i_stride - 1, i_stride,
i_thr[3], i_bin[3] );
-
-
+
+
/* 3: adaptive smoothing */
/* since we begin at (8,8) QP can be different for each block */
p_QP = &( p_QP_store[( y >> 4) * i_QP_stride + (x >> 4)] );
pp_dering_Filter( p_block[3], i_stride,
i_bin[3], p_QP[i_QP_stride+1] );
-
+
p_block[0] += 8;
p_block[1] += 8;
p_block[2] += 8;
p_block[3] += 8;
}
}
-
+
}
-void E_( pp_dering_C )( u8 *p_plane,
+void E_( pp_dering_C )( uint8_t *p_plane,
int i_width, int i_height, int i_stride,
QT_STORE_T *p_QP_store, int i_QP_stride )
{
int x, y;
int i_max, i_min;
int i_thr;
- u32 i_bin[10];
-
- u8 *p_block;
-
+ uint32_t i_bin[10];
+
+ uint8_t *p_block;
+
for( y = 8; y < i_height-8; y += 8 )
{
pp_dering_BinIndex( p_block - i_stride -1, i_stride,
i_thr,
i_bin );
-
+
/* 3: adaptive smoothing */
pp_dering_Filter( p_block, i_stride,
- i_bin,
+ i_bin,
p_QP_store[(y>>5)*i_QP_stride+ (x>>5)]);
p_block += 8;
}
}
-
+
}