Files
veejay/veejay-current/veejay-server/libvje/effects/raster.c
2019-09-08 15:08:29 +02:00

113 lines
3.0 KiB
C

/*
* Linux VeeJay
*
* Copyright(C)2002 Niels Elburg <nwelburg@gmail.com>
*
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 , USA.
*/
#include "common.h"
#include <veejaycore/vjmem.h>
#include "raster.h"
typedef struct {
int *xval;
} raster_t;
vj_effect *raster_init(int w, int h)
{
vj_effect *ve = (vj_effect *) vj_calloc(sizeof(vj_effect));
ve->num_params = 2;
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 */
ve->limits[0][0] = 4;
ve->limits[1][0] = h/4;
ve->limits[0][1] = 0;
ve->limits[1][1] = 1;
ve->defaults[0] = 4;
ve->defaults[1] = 1;
ve->description = "Grid";
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");
ve->hints = vje_init_value_hint_list( ve->num_params );
vje_build_value_hint_list( ve->hints, ve->limits[1][1], 1,"Black", "White" );
return ve;
}
void *raster_malloc (int w , int h)
{
raster_t *t = (raster_t*) vj_calloc(sizeof(raster_t));
if(!t) {
return NULL;
}
t->xval = vj_malloc(sizeof(int)*w);
if(!t->xval) {
free(t);
return NULL;
}
return (void*) t;
}
void raster_free(void *ptr)
{
raster_t *t = (raster_t*) ptr;
free(t->xval);
free(t);
}
void raster_apply(void *ptr, VJFrame *frame, int *args) {
int val = args[0];
int mode = args[1];
int x,y, yval;
uint8_t *Y = frame->data[0];
uint8_t *Cb= frame->data[1];
uint8_t *Cr= frame->data[2];
const unsigned int width = frame->width;
const unsigned int height = frame->height;
raster_t *t = (raster_t*) ptr;
int *xval = t->xval;
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] = ((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);
}
}
}