vje fix raster and flip

This commit is contained in:
Jerome Blanchi aka d.j.a.y
2019-05-28 15:54:09 +02:00
parent 05c01c11e6
commit 6934233aad
4 changed files with 52 additions and 145 deletions

View File

@@ -22,6 +22,8 @@
#include <libvjmem/vjmem.h>
#include "raster.h"
static int *xval;
vj_effect *raster_init(int w, int h)
{
vj_effect *ve = (vj_effect *) vj_calloc(sizeof(vj_effect));
@@ -37,7 +39,7 @@ vj_effect *raster_init(int w, int h)
ve->defaults[0] = 4;
ve->defaults[1] = 1;
ve->description = "Grid";
ve->sub_format = 0;
ve->sub_format = 1;
ve->extra_frame = 0;
ve->has_user = 0;
ve->param_description = vje_build_param_list( ve->num_params, "Grid size", "Mode");
@@ -48,9 +50,22 @@ vj_effect *raster_init(int w, int h)
return ve;
}
int raster_malloc (int w , int h)
{
xval = vj_malloc(sizeof(int)*w);
if (xval == NULL)
return 0;
return 1;
}
void raster_free()
{
if (xval == NULL) free(xval);
}
void raster_apply(VJFrame *frame, int val, int mode)
{
int x,y;
int x,y, yval;
uint8_t *Y = frame->data[0];
uint8_t *Cb= frame->data[1];
uint8_t *Cr= frame->data[2];
@@ -60,118 +75,21 @@ void raster_apply(VJFrame *frame, int val, int mode)
if(val == 0 )
return;
for(x=0; x < width; x++)
{
xval[x] = x%val;
}
uint8_t pixel_color = mode ? pixel_Y_hi_ : pixel_Y_lo_;
for(y=0; y < height; y++)
{
yval = y%val;
for(x=0; x < width; x++)
{
Y[y*width+x] = ((x%val>1)? ((y%val>1) ? Y[y*width+x]: pixel_color):pixel_color);
Y[y*width+x] = ((xval[x]>1)? ((yval>1) ? Y[y*width+x]: pixel_color):pixel_color);
Cb[y*width+x] = ((xval[x]>1)? ((yval>1) ? Cb[y*width+x]:128):128);
Cr[y*width+x] = ((xval[x]>1)? ((yval>1) ? Cr[y*width+x]:128):128);
}
}
const unsigned int uv_width= frame->uv_width;
const unsigned int uv_height= frame->uv_height;
for(y=0; y < uv_height; y++)
{
for(x=0; x < uv_width; x++)
{
Cb[y*uv_width+x] = ((x%val>1)? ((y%val>1) ? Cb[y*uv_width+x]:128):128);
Cr[y*uv_width+x] = ((x%val>1)? ((y%val>1) ? Cr[y*uv_width+x]:128):128);
}
}
/*
int x,y;
int px,py;
int i,j;
double r,a;
unsigned int R = h/2;
double curve; //curve
double coeef;
int w2 = w/2;
int h2 = h/2;
int n1=0,n2=0,n3=0;
int k,l,m,o1=0,o2=0;
double (*pf)(double a, double b, double c);
if( v==0) v =1;
if( v < 0 ) {
pf = &__fisheye_i;
v = v * -1;
}
else {
pf = &__fisheye;
}
curve = 0.001 * v; //curve
coeef = R / log(curve * R + 1);
if(!buf)
{
buf = (uint8_t*)vj_calloc(sizeof(uint8_t) * w * h );
if(!buf)return;
}
memcpy(buf, Y,(w*h));
for(y= (-1*h2); y < (h-h2); y++)
// for(y=0; y < h; y++)
//for(y=0; y < h; y++)
{
for(x = (-1*w2); x < (w-w2); x++)
// for(x=0 ;x < w; x++)
{
//if(x > 0 && y > 0)
//
if(x==0 && y==0) r = 0;
else r = sqrt( y*y+x*x);
if(x==0 && y==0)
a= 1;
else
a = atan2( (float)y,x);
//if(x > 0 && y < 0) a += 240;
//if(x < 0 && y > 0) a+= 180;
//if(x < 0 && y < 0) a+= 180;
i = (y+h2)*w+(w2+x);
if( r <= R)
{
//r = coeef * log(1 + curve * r);
r = pf( r, coeef, curve);
//px en py ook zonder +
px = (int) ( r * cos(a) );
py = (int) ( r * sin(a) );
px += w2;
py += h2;
if(px < 0) px =0;
if(px > w) px = w;
if(py < 0) py = 0;
if(py > (h-1)) py = h-1;
j = px + py * w;
//k = py * w + (w - px);
Y[i] = buf[j];
}
else
{
Y[i] = 16;
}
}
}
printf(" n1 = %d n2 = %d n3 = %d \n",n1,n2,n3);
memset(Cb,128,(w*h)/4);
memset(Cr,128,(w*h)/4);
*/
}