reduce number of calculations to improve performance

This commit is contained in:
veejay
2023-12-01 23:12:25 +01:00
parent c6a3b13ad6
commit 957da541c1

View File

@@ -111,18 +111,18 @@ void uvcorrect_free(void *ptr)
static inline void _chrominance_treatment(uvcorrect_t *uv, uint8_t *u,uint8_t *v, const int len) static inline void _chrominance_treatment(uvcorrect_t *uv, uint8_t *u,uint8_t *v, const int len)
{ {
uint8_t *Uu_c_p, *Vu_c_p; uint8_t *restrict Uu_c_p = u;
uint8_t *restrict Vu_c_p = v;
uint32_t i, base; uint32_t i, base;
Uu_c_p = u;
Vu_c_p = v;
// Chroma const uint8_t *restrict chroma = uv->chrominance;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
base = ((((uint32_t) * Uu_c_p) << 8) + (*Vu_c_p)) << 1; // base = ((((uint32_t)*Uu_c_p) * 256) + (*Vu_c_p)) * 2 base = ((((uint32_t) * Uu_c_p) << 8) + (*Vu_c_p)) << 1;
*(Uu_c_p++) = uv->chrominance[base++]; *(Uu_c_p++) = chroma[base++];
*(Vu_c_p++) = uv->chrominance[base]; *(Vu_c_p++) = chroma[base];
} }
} }
@@ -157,37 +157,26 @@ void uvcorrect_apply(void *ptr, VJFrame *frame, int *args )
for ( iU = 0; iU <= 255 ; iU ++ ) for ( iU = 0; iU <= 255 ; iU ++ )
{ {
float term = ( (float) (iU - centerU ) * Ufactor );
for( iV = 0; iV <= 255; iV ++ ) for( iV = 0; iV <= 255; iV ++ )
{ {
//U component //U component
fU = (((float) (iU - centerU ) * Ufactor ) * co - fU = ( (term * co) -
((float) (iV - centerV ) * Vfactor ) * si) + ((float) (iV - centerV ) * Vfactor ) * si) +
128.0; 128.0;
fU = (float) floor( 0.5 + fU ); fU = (float) floor( 0.5 + fU );
//clamp U values fU = ( fU < uvmin ? uvmin : fU > uvmax ? uvmax : fU );
if( fU < uvmin )
{
fU = uvmin;
}
if( fU > uvmax )
{
fU = uvmax;
}
//V component
fV = (((float) ( iV - centerV) * Vfactor ) * co + //V component
((float) ( iU - centerU) * Ufactor ) * si ) + fV = ((float) (iV - centerV ) * Vfactor ) * co +
(term * si ) +
128.0; 128.0;
fV = (float) floor( 0.5 + fV ); fV = (float) floor( 0.5 + fV );
//clamp V values fV = ( fV < uvmin ? uvmin : fU > uvmax ? uvmax: fV );
if( fV < uvmin )
fV = uvmin;
if( fV > uvmax )
fV = uvmax;
//store in vector //store in vector
*(table)++ = (uint8_t) fU; *(table)++ = (uint8_t) fU;