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