Skip to content

Commit

Permalink
Image support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Bourdeauducq committed Nov 23, 2011
1 parent 9aa2377 commit 4d2416d
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 16 deletions.
16 changes: 15 additions & 1 deletion src/renderer/compiler.c
Expand Up @@ -161,7 +161,16 @@ static const char pfv_names[COMP_PFV_COUNT][FPVM_MAXSYMLEN] = {
"midi7",
"midi8",

"video_a"
"video_a",

"image1_a",
"image1_x",
"image1_y",
"image1_zoom",
"image2_a",
"image2_x",
"image2_y",
"image2_zoom"
};

static int pfv_from_name(struct compiler_sc *sc, const char *name)
Expand Down Expand Up @@ -216,6 +225,11 @@ static void load_defaults(struct compiler_sc *sc)
sc->p->pfv_initial[pfv_mv_l] = 1.0;

sc->p->pfv_initial[pfv_warp_scale] = 1.0;

sc->p->pfv_initial[pfv_video_echo_zoom] = 1.0;

sc->p->pfv_initial[pfv_image1_zoom] = 1.0;
sc->p->pfv_initial[pfv_image2_zoom] = 1.0;
}

static void set_initial(struct compiler_sc *sc, int pfv, float x)
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/compiler.h
Expand Up @@ -128,6 +128,15 @@ enum {
pfv_midi8,

pfv_video_a,

pfv_image1_a,
pfv_image1_x,
pfv_image1_y,
pfv_image1_zoom,
pfv_image2_a,
pfv_image2_x,
pfv_image2_y,
pfv_image2_zoom,

COMP_PFV_COUNT /* must be last */
};
Expand Down
19 changes: 18 additions & 1 deletion src/renderer/eval.c
Expand Up @@ -27,6 +27,7 @@
#include <bsp/milkymist_pfpu.h>
#include <bsp/milkymist_tmu.h>

#include "../pixbuf/pixbuf.h"
#include "compiler.h"
#include "framedescriptor.h"
#include "renderer.h"
Expand Down Expand Up @@ -221,6 +222,15 @@ static void set_frd_from_pfv(struct patch *p, struct frame_descriptor *frd)
frd->dmx[7] = read_pfv(p, pfv_dmx8);

frd->video_a = read_pfv(p, pfv_video_a);

frd->image_a[0] = read_pfv(p, pfv_image1_a);
frd->image_x[0] = read_pfv(p, pfv_image1_x);
frd->image_y[0] = read_pfv(p, pfv_image1_y);
frd->image_zoom[0] = read_pfv(p, pfv_image1_zoom);
frd->image_a[1] = read_pfv(p, pfv_image2_a);
frd->image_x[1] = read_pfv(p, pfv_image2_x);
frd->image_y[1] = read_pfv(p, pfv_image2_y);
frd->image_zoom[1] = read_pfv(p, pfv_image2_zoom);
}

static unsigned int pfpudummy[2] __attribute__((aligned(sizeof(struct tmu_vertex))));
Expand Down Expand Up @@ -278,6 +288,7 @@ static rtems_task eval_task(rtems_task_argument argument)

while(1) {
struct patch *p;
int i;

rtems_message_queue_receive(
eval_q,
Expand All @@ -294,7 +305,13 @@ static rtems_task eval_task(rtems_task_argument argument)
renderer_lock_patch();

p = renderer_get_patch(1);


/* NB: we do not increment reference count and assume pixbufs
* will be valid until the renderer has fully stopped.
*/
for(i=0;i<IMAGE_COUNT;i++)
frd->images[i] = p->images[i];

reinit_all_pfv(p);
set_pfv_from_frd(p, frd);
eval_pfv(p, pfpu_fd);
Expand Down
95 changes: 81 additions & 14 deletions src/renderer/raster.c
Expand Up @@ -365,7 +365,7 @@ static void compute_wave_vertices(struct frame_descriptor *frd, struct wave_para
}
}

static void draw(unsigned short *fb, struct frame_descriptor *frd, struct wave_params *params, struct wave_vertex *vertices, int nvertices)
static void software_draw(unsigned short *fb, struct frame_descriptor *frd, struct wave_params *params, struct wave_vertex *vertices, int nvertices)
{
draw_motion_vectors(fb, frd);
draw_borders(fb, frd);
Expand Down Expand Up @@ -488,6 +488,83 @@ static void video(unsigned short *tex_backbuffer, struct frame_descriptor *frd,
ioctl(video_fd, VIDEO_BUFFER_UNLOCK, videoframe);
}

static void images(unsigned short *tex_backbuffer, struct frame_descriptor *frd, int tmu_fd, struct tmu_vertex *scale_vertices)
{
int i;
struct tmu_td td;
int alpha;
float ftexsize;
int dx, dy;
int sx, sy;

for(i=0;i<IMAGE_COUNT;i++) {
if((frd->images[i] != NULL) && (frd->image_a[i] != 0.0)) {
alpha = 64.0*frd->image_a[i];
alpha--;
if(alpha > TMU_ALPHA_MAX)
alpha = TMU_ALPHA_MAX;
if(alpha <= 0)
continue;

ftexsize = (float)renderer_texsize;
dx = ftexsize*frd->image_x[i];
dx = ftexsize*frd->image_y[i];
sx = ((float)frd->images[i]->width)*frd->image_zoom[i];
sy = ((float)frd->images[i]->height)*frd->image_zoom[i];

scale_vertices[0].x = 0;
scale_vertices[0].y = 0;
scale_vertices[1].x = frd->images[i]->width << TMU_FIXEDPOINT_SHIFT;
scale_vertices[1].y = 0;
scale_vertices[TMU_MESH_MAXSIZE].x = 0;
scale_vertices[TMU_MESH_MAXSIZE].y = frd->images[i]->height << TMU_FIXEDPOINT_SHIFT;
scale_vertices[TMU_MESH_MAXSIZE+1].x = frd->images[i]->width << TMU_FIXEDPOINT_SHIFT;
scale_vertices[TMU_MESH_MAXSIZE+1].y = frd->images[i]->height << TMU_FIXEDPOINT_SHIFT;

td.flags = 0;
td.hmeshlast = 1;
td.vmeshlast = 1;
td.brightness = TMU_BRIGHTNESS_MAX;
td.chromakey = 0;
td.vertices = scale_vertices;
td.texfbuf = frd->images[i]->pixels;
td.texhres = frd->images[i]->width;
td.texvres = frd->images[i]->height;
td.texhmask = TMU_MASK_FULL;
td.texvmask = TMU_MASK_FULL;
td.dstfbuf = tex_backbuffer;
td.dsthres = renderer_texsize;
td.dstvres = renderer_texsize;
td.dsthoffset = dx - (sx >> 1);
td.dstvoffset = dy - (sy >> 1);
td.dstsquarew = sx;
td.dstsquareh = sy;
td.alpha = alpha;
td.invalidate_before = false;
td.invalidate_after = false;

ioctl(tmu_fd, TMU_EXECUTE, &td);
}
}
}

static void update_dmx_outputs(int dmx_fd, struct frame_descriptor *frd, int *dmx_map)
{
int i;
unsigned char dmx_val;

for(i=0;i<DMX_COUNT;i++) {
lseek(dmx_fd, dmx_map[i], SEEK_SET);
if(frd->dmx[i] > 1.0)
dmx_val = 255;
else if(frd->dmx[i] < 0.0)
dmx_val = 0;
else
dmx_val = frd->dmx[i]*255.0;
write(dmx_fd, &dmx_val, 1);
}
}

struct raster_task_param {
int framebuffer_fd;
int dmx_map[DMX_COUNT];
Expand Down Expand Up @@ -518,8 +595,6 @@ static rtems_task raster_task(rtems_task_argument argument)
struct wave_vertex vertices[256];
int nvertices;
int vecho_alpha;
int i;
unsigned char dmx_val;

status = posix_memalign((void **)&tex_frontbuffer, 32,
2*renderer_texsize*renderer_texsize);
Expand Down Expand Up @@ -576,8 +651,9 @@ static rtems_task raster_task(rtems_task_argument argument)
warp(tmu_fd, tex_frontbuffer, tex_backbuffer, frd->vertices, frd->tex_wrap, ibrightness);
compute_wave_vertices(frd, &params, vertices, &nvertices);
ioctl(tmu_fd, TMU_EXECUTE_WAIT);
draw(tex_backbuffer, frd, &params, vertices, nvertices);
software_draw(tex_backbuffer, frd, &params, vertices, nvertices);
video(tex_backbuffer, frd, tmu_fd, video_fd, scale_vertices);
images(tex_backbuffer, frd, tmu_fd, scale_vertices);

/* Scale and send to screen */
screen_backbuffer = get_screen_backbuffer(param->framebuffer_fd);
Expand All @@ -595,16 +671,7 @@ static rtems_task raster_task(rtems_task_argument argument)
ioctl(param->framebuffer_fd, FBIOSWAPBUFFERS);

/* Update DMX outputs */
for(i=0;i<DMX_COUNT;i++) {
lseek(dmx_fd, param->dmx_map[i], SEEK_SET);
if(frd->dmx[i] > 1.0)
dmx_val = 255;
else if(frd->dmx[i] < 0.0)
dmx_val = 0;
else
dmx_val = frd->dmx[i]*255.0;
write(dmx_fd, &dmx_val, 1);
}
update_dmx_outputs(dmx_fd, frd, param->dmx_map);

/* Swap texture buffers */
p = tex_frontbuffer;
Expand Down

0 comments on commit 4d2416d

Please sign in to comment.