mirror of
https://github.com/game-stop/veejay.git
synced 2025-12-05 15:30:02 +01:00
reduce number of calculations to improve performance
This commit is contained in:
@@ -49,10 +49,10 @@ vj_effect *uvcorrect_init(int w, int h)
|
||||
vj_effect *ve = (vj_effect *) vj_calloc(sizeof(vj_effect));
|
||||
ve->num_params = 7;
|
||||
|
||||
ve->defaults = (int *) vj_calloc(sizeof(int) * ve->num_params); /* default values */
|
||||
ve->limits[0] = (int *) vj_calloc(sizeof(int) * ve->num_params); /* min */
|
||||
ve->limits[1] = (int *) vj_calloc(sizeof(int) * ve->num_params); /* max */
|
||||
//angle,r,g,b,cbc,crc
|
||||
ve->defaults = (int *) vj_calloc(sizeof(int) * ve->num_params); /* default values */
|
||||
ve->limits[0] = (int *) vj_calloc(sizeof(int) * ve->num_params); /* min */
|
||||
ve->limits[1] = (int *) vj_calloc(sizeof(int) * ve->num_params); /* max */
|
||||
//angle,r,g,b,cbc,crc
|
||||
|
||||
ve->limits[0][0] = 1;
|
||||
ve->limits[1][0] = 360;
|
||||
@@ -67,7 +67,7 @@ vj_effect *uvcorrect_init(int w, int h)
|
||||
ve->limits[0][5] = 0;
|
||||
ve->limits[1][5] = 255;
|
||||
ve->limits[0][6] = 0;
|
||||
ve->limits[1][6] = 255;
|
||||
ve->limits[1][6] = 255;
|
||||
|
||||
ve->defaults[0] = 1;
|
||||
ve->defaults[1] = 128;
|
||||
@@ -77,13 +77,13 @@ vj_effect *uvcorrect_init(int w, int h)
|
||||
ve->defaults[5] = pixel_U_lo_;
|
||||
ve->defaults[6] = pixel_U_hi_;
|
||||
ve->description = "U/V Correction";
|
||||
ve->param_description = vje_build_param_list( ve->num_params, "Angle" ,"U Rotate Center", "V Rotate Center",
|
||||
"Intensity U", "Intensity V", "Minimum UV", "Maximum UV");
|
||||
ve->param_description = vje_build_param_list( ve->num_params, "Angle" ,"U Rotate Center", "V Rotate Center",
|
||||
"Intensity U", "Intensity V", "Minimum UV", "Maximum UV");
|
||||
|
||||
ve->sub_format = -1;
|
||||
ve->extra_frame = 0;
|
||||
ve->has_help = 1;
|
||||
ve->has_user = 0;
|
||||
ve->has_user = 0;
|
||||
|
||||
return ve;
|
||||
}
|
||||
@@ -94,48 +94,48 @@ void *uvcorrect_malloc(int w, int h )
|
||||
if(!uv) {
|
||||
return NULL;
|
||||
}
|
||||
uv->chrominance = (uint8_t*) vj_malloc (sizeof(uint8_t) * 2 * 256 * 256 );
|
||||
if(!uv->chrominance) {
|
||||
uv->chrominance = (uint8_t*) vj_malloc (sizeof(uint8_t) * 2 * 256 * 256 );
|
||||
if(!uv->chrominance) {
|
||||
free(uv);
|
||||
return NULL;
|
||||
}
|
||||
return uv;
|
||||
return uv;
|
||||
}
|
||||
|
||||
void uvcorrect_free(void *ptr)
|
||||
void uvcorrect_free(void *ptr)
|
||||
{
|
||||
uvcorrect_t *uv = (uvcorrect_t*) ptr;
|
||||
if(uv->chrominance) free(uv->chrominance);
|
||||
free(uv);
|
||||
free(uv);
|
||||
}
|
||||
|
||||
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;
|
||||
uint32_t i, base;
|
||||
uint8_t *restrict Uu_c_p = u;
|
||||
uint8_t *restrict Vu_c_p = v;
|
||||
uint32_t i, base;
|
||||
|
||||
Uu_c_p = u;
|
||||
Vu_c_p = v;
|
||||
|
||||
// Chroma
|
||||
for (i = 0; i < len; i++)
|
||||
const uint8_t *restrict chroma = uv->chrominance;
|
||||
|
||||
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
|
||||
*(Uu_c_p++) = uv->chrominance[base++];
|
||||
*(Vu_c_p++) = uv->chrominance[base];
|
||||
base = ((((uint32_t) * Uu_c_p) << 8) + (*Vu_c_p)) << 1;
|
||||
*(Uu_c_p++) = chroma[base++];
|
||||
*(Vu_c_p++) = chroma[base];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void uvcorrect_apply(void *ptr, VJFrame *frame, int *args )
|
||||
{
|
||||
float fU,fV,si,co;
|
||||
uint16_t iU,iV;
|
||||
float fU,fV,si,co;
|
||||
uint16_t iU,iV;
|
||||
uvcorrect_t *uv = (uvcorrect_t*) ptr;
|
||||
uint8_t *Uplane = frame->data[1];
|
||||
uint8_t *Vplane = frame->data[2];
|
||||
// chrominance vector
|
||||
uint8_t *table = uv->chrominance;
|
||||
uint8_t *Uplane = frame->data[1];
|
||||
uint8_t *Vplane = frame->data[2];
|
||||
// chrominance vector
|
||||
uint8_t *table = uv->chrominance;
|
||||
int angle = args[0];
|
||||
int urot_center = args[1];
|
||||
int vrot_center = args[2];
|
||||
@@ -143,59 +143,48 @@ void uvcorrect_apply(void *ptr, VJFrame *frame, int *args )
|
||||
int ivFactor = args[4];
|
||||
int uv_min = args[5];
|
||||
int uv_max = args[6];
|
||||
const uint8_t centerU = urot_center;
|
||||
const uint8_t centerV = vrot_center;
|
||||
const float Ufactor = (float)iuFactor * 0.1;
|
||||
const float Vfactor = (float)ivFactor * 0.1;
|
||||
const int uv_len = (frame->ssm ? frame->len : frame->uv_len);
|
||||
const uint8_t uvmin = (uint8_t) uv_min;
|
||||
const uint8_t uvmax = (uint8_t) uv_max;
|
||||
const float f_angle = (float) angle / 180.0 * M_PI;
|
||||
const uint8_t centerU = urot_center;
|
||||
const uint8_t centerV = vrot_center;
|
||||
const float Ufactor = (float)iuFactor * 0.1;
|
||||
const float Vfactor = (float)ivFactor * 0.1;
|
||||
const int uv_len = (frame->ssm ? frame->len : frame->uv_len);
|
||||
const uint8_t uvmin = (uint8_t) uv_min;
|
||||
const uint8_t uvmax = (uint8_t) uv_max;
|
||||
const float f_angle = (float) angle / 180.0 * M_PI;
|
||||
|
||||
sin_cos ( si, co, f_angle );
|
||||
sin_cos ( si, co, f_angle );
|
||||
|
||||
|
||||
for ( iU = 0; iU <= 255 ; iU ++ )
|
||||
{
|
||||
for( iV = 0; iV <= 255; iV ++ )
|
||||
{
|
||||
//U component
|
||||
fU = (((float) (iU - centerU ) * Ufactor ) * co -
|
||||
((float) (iV - centerV ) * Vfactor ) * si) +
|
||||
128.0;
|
||||
for ( iU = 0; iU <= 255 ; iU ++ )
|
||||
{
|
||||
float term = ( (float) (iU - centerU ) * Ufactor );
|
||||
for( iV = 0; iV <= 255; iV ++ )
|
||||
{
|
||||
//U component
|
||||
fU = ( (term * co) -
|
||||
((float) (iV - centerV ) * Vfactor ) * si) +
|
||||
128.0;
|
||||
|
||||
fU = (float) floor( 0.5 + fU );
|
||||
fU = (float) floor( 0.5 + fU );
|
||||
|
||||
//clamp U values
|
||||
if( fU < uvmin )
|
||||
{
|
||||
fU = uvmin;
|
||||
}
|
||||
if( fU > uvmax )
|
||||
{
|
||||
fU = uvmax;
|
||||
}
|
||||
//V component
|
||||
fU = ( fU < uvmin ? uvmin : fU > uvmax ? uvmax : fU );
|
||||
|
||||
fV = (((float) ( iV - centerV) * Vfactor ) * co +
|
||||
((float) ( iU - centerU) * Ufactor ) * si ) +
|
||||
128.0;
|
||||
//V component
|
||||
fV = ((float) (iV - centerV ) * Vfactor ) * co +
|
||||
(term * si ) +
|
||||
128.0;
|
||||
|
||||
fV = (float) floor( 0.5 + fV );
|
||||
fV = (float) floor( 0.5 + fV );
|
||||
|
||||
//clamp V values
|
||||
if( fV < uvmin )
|
||||
fV = uvmin;
|
||||
if( fV > uvmax )
|
||||
fV = uvmax;
|
||||
fV = ( fV < uvmin ? uvmin : fU > uvmax ? uvmax: fV );
|
||||
|
||||
//store in vector
|
||||
*(table)++ = (uint8_t) fU;
|
||||
*(table)++ = (uint8_t) fV;
|
||||
}
|
||||
}
|
||||
//store in vector
|
||||
*(table)++ = (uint8_t) fU;
|
||||
*(table)++ = (uint8_t) fV;
|
||||
}
|
||||
}
|
||||
|
||||
_chrominance_treatment( uv, Uplane,Vplane , uv_len );
|
||||
_chrominance_treatment( uv, Uplane,Vplane , uv_len );
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user