Skip to content

Commit 4d2416d

Browse files
author
Sebastien Bourdeauducq
committedNov 23, 2011
Image support
1 parent 9aa2377 commit 4d2416d

File tree

4 files changed

+123
-16
lines changed

4 files changed

+123
-16
lines changed
 

‎src/renderer/compiler.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ static const char pfv_names[COMP_PFV_COUNT][FPVM_MAXSYMLEN] = {
161161
"midi7",
162162
"midi8",
163163

164-
"video_a"
164+
"video_a",
165+
166+
"image1_a",
167+
"image1_x",
168+
"image1_y",
169+
"image1_zoom",
170+
"image2_a",
171+
"image2_x",
172+
"image2_y",
173+
"image2_zoom"
165174
};
166175

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

218227
sc->p->pfv_initial[pfv_warp_scale] = 1.0;
228+
229+
sc->p->pfv_initial[pfv_video_echo_zoom] = 1.0;
230+
231+
sc->p->pfv_initial[pfv_image1_zoom] = 1.0;
232+
sc->p->pfv_initial[pfv_image2_zoom] = 1.0;
219233
}
220234

221235
static void set_initial(struct compiler_sc *sc, int pfv, float x)

‎src/renderer/compiler.h

+9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ enum {
128128
pfv_midi8,
129129

130130
pfv_video_a,
131+
132+
pfv_image1_a,
133+
pfv_image1_x,
134+
pfv_image1_y,
135+
pfv_image1_zoom,
136+
pfv_image2_a,
137+
pfv_image2_x,
138+
pfv_image2_y,
139+
pfv_image2_zoom,
131140

132141
COMP_PFV_COUNT /* must be last */
133142
};

‎src/renderer/eval.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <bsp/milkymist_pfpu.h>
2828
#include <bsp/milkymist_tmu.h>
2929

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

223224
frd->video_a = read_pfv(p, pfv_video_a);
225+
226+
frd->image_a[0] = read_pfv(p, pfv_image1_a);
227+
frd->image_x[0] = read_pfv(p, pfv_image1_x);
228+
frd->image_y[0] = read_pfv(p, pfv_image1_y);
229+
frd->image_zoom[0] = read_pfv(p, pfv_image1_zoom);
230+
frd->image_a[1] = read_pfv(p, pfv_image2_a);
231+
frd->image_x[1] = read_pfv(p, pfv_image2_x);
232+
frd->image_y[1] = read_pfv(p, pfv_image2_y);
233+
frd->image_zoom[1] = read_pfv(p, pfv_image2_zoom);
224234
}
225235

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

279289
while(1) {
280290
struct patch *p;
291+
int i;
281292

282293
rtems_message_queue_receive(
283294
eval_q,
@@ -294,7 +305,13 @@ static rtems_task eval_task(rtems_task_argument argument)
294305
renderer_lock_patch();
295306

296307
p = renderer_get_patch(1);
297-
308+
309+
/* NB: we do not increment reference count and assume pixbufs
310+
* will be valid until the renderer has fully stopped.
311+
*/
312+
for(i=0;i<IMAGE_COUNT;i++)
313+
frd->images[i] = p->images[i];
314+
298315
reinit_all_pfv(p);
299316
set_pfv_from_frd(p, frd);
300317
eval_pfv(p, pfpu_fd);

‎src/renderer/raster.c

+81-14
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void compute_wave_vertices(struct frame_descriptor *frd, struct wave_para
365365
}
366366
}
367367

368-
static void draw(unsigned short *fb, struct frame_descriptor *frd, struct wave_params *params, struct wave_vertex *vertices, int nvertices)
368+
static void software_draw(unsigned short *fb, struct frame_descriptor *frd, struct wave_params *params, struct wave_vertex *vertices, int nvertices)
369369
{
370370
draw_motion_vectors(fb, frd);
371371
draw_borders(fb, frd);
@@ -488,6 +488,83 @@ static void video(unsigned short *tex_backbuffer, struct frame_descriptor *frd,
488488
ioctl(video_fd, VIDEO_BUFFER_UNLOCK, videoframe);
489489
}
490490

491+
static void images(unsigned short *tex_backbuffer, struct frame_descriptor *frd, int tmu_fd, struct tmu_vertex *scale_vertices)
492+
{
493+
int i;
494+
struct tmu_td td;
495+
int alpha;
496+
float ftexsize;
497+
int dx, dy;
498+
int sx, sy;
499+
500+
for(i=0;i<IMAGE_COUNT;i++) {
501+
if((frd->images[i] != NULL) && (frd->image_a[i] != 0.0)) {
502+
alpha = 64.0*frd->image_a[i];
503+
alpha--;
504+
if(alpha > TMU_ALPHA_MAX)
505+
alpha = TMU_ALPHA_MAX;
506+
if(alpha <= 0)
507+
continue;
508+
509+
ftexsize = (float)renderer_texsize;
510+
dx = ftexsize*frd->image_x[i];
511+
dx = ftexsize*frd->image_y[i];
512+
sx = ((float)frd->images[i]->width)*frd->image_zoom[i];
513+
sy = ((float)frd->images[i]->height)*frd->image_zoom[i];
514+
515+
scale_vertices[0].x = 0;
516+
scale_vertices[0].y = 0;
517+
scale_vertices[1].x = frd->images[i]->width << TMU_FIXEDPOINT_SHIFT;
518+
scale_vertices[1].y = 0;
519+
scale_vertices[TMU_MESH_MAXSIZE].x = 0;
520+
scale_vertices[TMU_MESH_MAXSIZE].y = frd->images[i]->height << TMU_FIXEDPOINT_SHIFT;
521+
scale_vertices[TMU_MESH_MAXSIZE+1].x = frd->images[i]->width << TMU_FIXEDPOINT_SHIFT;
522+
scale_vertices[TMU_MESH_MAXSIZE+1].y = frd->images[i]->height << TMU_FIXEDPOINT_SHIFT;
523+
524+
td.flags = 0;
525+
td.hmeshlast = 1;
526+
td.vmeshlast = 1;
527+
td.brightness = TMU_BRIGHTNESS_MAX;
528+
td.chromakey = 0;
529+
td.vertices = scale_vertices;
530+
td.texfbuf = frd->images[i]->pixels;
531+
td.texhres = frd->images[i]->width;
532+
td.texvres = frd->images[i]->height;
533+
td.texhmask = TMU_MASK_FULL;
534+
td.texvmask = TMU_MASK_FULL;
535+
td.dstfbuf = tex_backbuffer;
536+
td.dsthres = renderer_texsize;
537+
td.dstvres = renderer_texsize;
538+
td.dsthoffset = dx - (sx >> 1);
539+
td.dstvoffset = dy - (sy >> 1);
540+
td.dstsquarew = sx;
541+
td.dstsquareh = sy;
542+
td.alpha = alpha;
543+
td.invalidate_before = false;
544+
td.invalidate_after = false;
545+
546+
ioctl(tmu_fd, TMU_EXECUTE, &td);
547+
}
548+
}
549+
}
550+
551+
static void update_dmx_outputs(int dmx_fd, struct frame_descriptor *frd, int *dmx_map)
552+
{
553+
int i;
554+
unsigned char dmx_val;
555+
556+
for(i=0;i<DMX_COUNT;i++) {
557+
lseek(dmx_fd, dmx_map[i], SEEK_SET);
558+
if(frd->dmx[i] > 1.0)
559+
dmx_val = 255;
560+
else if(frd->dmx[i] < 0.0)
561+
dmx_val = 0;
562+
else
563+
dmx_val = frd->dmx[i]*255.0;
564+
write(dmx_fd, &dmx_val, 1);
565+
}
566+
}
567+
491568
struct raster_task_param {
492569
int framebuffer_fd;
493570
int dmx_map[DMX_COUNT];
@@ -518,8 +595,6 @@ static rtems_task raster_task(rtems_task_argument argument)
518595
struct wave_vertex vertices[256];
519596
int nvertices;
520597
int vecho_alpha;
521-
int i;
522-
unsigned char dmx_val;
523598

524599
status = posix_memalign((void **)&tex_frontbuffer, 32,
525600
2*renderer_texsize*renderer_texsize);
@@ -576,8 +651,9 @@ static rtems_task raster_task(rtems_task_argument argument)
576651
warp(tmu_fd, tex_frontbuffer, tex_backbuffer, frd->vertices, frd->tex_wrap, ibrightness);
577652
compute_wave_vertices(frd, &params, vertices, &nvertices);
578653
ioctl(tmu_fd, TMU_EXECUTE_WAIT);
579-
draw(tex_backbuffer, frd, &params, vertices, nvertices);
654+
software_draw(tex_backbuffer, frd, &params, vertices, nvertices);
580655
video(tex_backbuffer, frd, tmu_fd, video_fd, scale_vertices);
656+
images(tex_backbuffer, frd, tmu_fd, scale_vertices);
581657

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

597673
/* Update DMX outputs */
598-
for(i=0;i<DMX_COUNT;i++) {
599-
lseek(dmx_fd, param->dmx_map[i], SEEK_SET);
600-
if(frd->dmx[i] > 1.0)
601-
dmx_val = 255;
602-
else if(frd->dmx[i] < 0.0)
603-
dmx_val = 0;
604-
else
605-
dmx_val = frd->dmx[i]*255.0;
606-
write(dmx_fd, &dmx_val, 1);
607-
}
674+
update_dmx_outputs(dmx_fd, frd, param->dmx_map);
608675

609676
/* Swap texture buffers */
610677
p = tex_frontbuffer;

0 commit comments

Comments
 (0)
Please sign in to comment.