int visual_video_init (VisVideo *video) { visual_return_val_if_fail (video != NULL, -VISUAL_ERROR_VIDEO_NULL); /* Do the VisObject initialization */ visual_object_clear (VISUAL_OBJECT (video)); visual_object_set_dtor (VISUAL_OBJECT (video), video_dtor); visual_object_set_allocated (VISUAL_OBJECT (video), FALSE); /* Reset the VisVideo data */ video->buffer = visual_buffer_new (); video->pixel_rows = NULL; visual_video_set_attributes (video, 0, 0, 0, VISUAL_VIDEO_DEPTH_NONE); visual_video_set_buffer (video, NULL); visual_video_set_palette (video, NULL); video->parent = NULL; video->rect = visual_rectangle_new_empty (); /* Composite control */ video->compositetype = VISUAL_VIDEO_COMPOSITE_TYPE_SRC; /* Colors */ video->colorkey = visual_color_new (); return VISUAL_OK; }
int visual_morph_run (VisMorph *morph, VisAudio *audio, VisVideo *src1, VisVideo *src2) { VisMorphPlugin *morphplugin; visual_return_val_if_fail (morph != NULL, -VISUAL_ERROR_MORPH_NULL); visual_return_val_if_fail (audio != NULL, -VISUAL_ERROR_AUDIO_NULL); visual_return_val_if_fail (src1 != NULL, -VISUAL_ERROR_VIDEO_NULL); visual_return_val_if_fail (src2 != NULL, -VISUAL_ERROR_VIDEO_NULL); morphplugin = get_morph_plugin (morph); if (morphplugin == NULL) { visual_log (VISUAL_LOG_ERROR, _("The given morph does not reference any plugin")); return -VISUAL_ERROR_MORPH_PLUGIN_NULL; } /* If we're morphing using the timer, start the timer. */ if (!visual_timer_is_active (morph->timer)) visual_timer_start (morph->timer); if (morphplugin->palette != NULL) morphplugin->palette (morph->plugin, morph->rate, audio, morph->morphpal, src1, src2); else { if (src1->pal != NULL && src2->pal != NULL) visual_palette_blend (morph->morphpal, src1->pal, src2->pal, morph->rate); } morphplugin->apply (morph->plugin, morph->rate, audio, morph->dest, src1, src2); visual_video_set_palette (morph->dest, visual_morph_get_palette (morph)); /* On automatic morphing increase the rate. */ if (morph->mode == VISUAL_MORPH_MODE_STEPS) { morph->rate += (1.000 / morph->steps); morph->stepsdone++; if (morph->rate > 1.0) morph->rate = 1; } else if (morph->mode == VISUAL_MORPH_MODE_TIME) { /** * @todo: We might want to have a bigger type here, but long longs aren't atomic * on most architectures, so that won't do for now, maybe when we can lock (for threading) * we can look into that */ double usec_elapsed = visual_timer_elapsed_usecs (morph->timer); double usec_morph = visual_time_to_usecs (morph->morphtime); morph->rate = usec_elapsed / usec_morph; if (morph->rate > 1.0) morph->rate = 1; } return VISUAL_OK; }
int main (int argc, char **argv) { char *d1, *d2; VisVideo *dest, *src; VisVideoDepth depth1, depth2; int i; visual_init (&argc, &argv); if (argc > 2) { d1 = argv[1]; d2 = argv[2]; } else { d1 = strdup("32"); d2 = strdup("16"); } depth1 = visual_video_depth_enum_from_value(atoi(d1)); depth2 = visual_video_depth_enum_from_value(atoi(d2)); dest = visual_video_new (); visual_video_set_depth (dest, depth1); visual_video_set_dimension (dest, 640, 400); visual_video_set_palette (dest, visual_palette_new (256)); visual_video_allocate_buffer (dest); src = visual_video_new (); visual_video_set_depth (src, depth2); visual_video_set_dimension (src, 640, 400); visual_video_set_palette (src, visual_palette_new (256)); visual_video_allocate_buffer (src); for (i = 0; i < TIMES; i++) visual_video_depth_transform (dest, src); printf ("Depth transformed %d times from %s to %s\n", TIMES, d1, d2); }
/** * This is called to run a VisActor. It also pump it's events when needed, checks for new song events and also does the fitting * and depth transformation actions when needed. * * Every run cycle one frame is created, so this function needs to be used in the main draw loop of the application. * * @param actor Pointer to a VisActor that needs to be runned. * @param audio Pointer to a VisAudio that contains all the audio data. * * return VISUAL_OK on succes, -VISUAL_ERROR_ACTOR_NULL, -VISUAL_ERROR_ACTOR_VIDEO_NULL, -VISUAL_ERROR_NULL or * -VISUAL_ERROR_ACTOR_PLUGIN_NULL on failure. */ int visual_actor_run (VisActor *actor, VisAudio *audio) { VisActorPlugin *actplugin; VisPluginData *plugin; VisVideo *video; VisVideo *transform; VisVideo *fitting; /* We don't check for video, because we don't always need a video */ /* * Really? take a look at visual_video_set_palette bellow */ visual_log_return_val_if_fail (actor != NULL, -VISUAL_ERROR_ACTOR_NULL); visual_log_return_val_if_fail (actor->video != NULL, -VISUAL_ERROR_ACTOR_VIDEO_NULL); visual_log_return_val_if_fail (audio != NULL, -VISUAL_ERROR_NULL); actplugin = get_actor_plugin (actor); plugin = visual_actor_get_plugin (actor); if (actplugin == NULL) { visual_log (VISUAL_LOG_CRITICAL, _("The given actor does not reference any actor plugin")); return -VISUAL_ERROR_ACTOR_PLUGIN_NULL; } /* Songinfo handling */ if(0) /*FIXME*/if (visual_songinfo_compare (&actor->songcompare, &actplugin->songinfo) == FALSE || actor->songcompare.elapsed != actplugin->songinfo.elapsed) { visual_songinfo_mark (&actplugin->songinfo); visual_event_queue_add_newsong ( visual_plugin_get_eventqueue (plugin), &actplugin->songinfo); visual_songinfo_free_strings (&actor->songcompare); visual_songinfo_copy (&actor->songcompare, &actplugin->songinfo); } video = actor->video; transform = actor->transform; fitting = actor->fitting; /* * This needs to happen before palette, render stuff, always, period. * Also internal vars can be initialized when params have been set in init on the param * events in the event loop. */ visual_plugin_events_pump (actor->plugin); visual_video_set_palette (video, visual_actor_get_palette (actor)); /* Set the palette to the target video */ video->pal = visual_actor_get_palette (actor); /* Yeah some transformation magic is going on here when needed */ if (transform != NULL && (transform->depth != video->depth)) { actplugin->render (plugin, transform, audio); if (transform->depth == VISUAL_VIDEO_DEPTH_8BIT) { visual_video_set_palette (transform, visual_actor_get_palette (actor)); visual_video_depth_transform (video, transform); } else { visual_video_set_palette (transform, actor->ditherpal); visual_video_depth_transform (video, transform); } } else { if (fitting != NULL && (fitting->width != video->width || fitting->height != video->height)) { actplugin->render (plugin, fitting, audio); visual_video_blit_overlay (video, fitting, 0, 0, FALSE); } else { actplugin->render (plugin, video, audio); } } return VISUAL_OK; }
/* Main stuff */ int main (int argc, char *argv[]) { int width = 1000, height = 600; int i, j; int freeze = 0; int depthflag = 0; int alpha = 128; bpp = 4; sdl_init (width, height); scrbuf = malloc (screen->pitch * screen->h); memset (scrbuf, 0, screen->pitch * screen->h); SDL_Event event; visual_init (&argc, &argv); if (argc > 1) actor = visual_actor_new (argv[1]); else actor = visual_actor_new ("G-Force"); visual_actor_realize (actor); video = visual_video_new (); visual_actor_set_video (actor, video); visual_video_set_depth (video, VISUAL_VIDEO_DEPTH_32BIT); visual_video_set_dimension (video, 256, 256); visual_video_allocate_buffer (video); visual_actor_video_negotiate (actor, 0, FALSE, FALSE); scalevid = visual_video_new (); visual_video_set_depth (scalevid, VISUAL_VIDEO_DEPTH_32BIT); visual_video_set_dimension (scalevid, 300, 400); visual_video_allocate_buffer (scalevid); sdlvid = visual_video_new (); visual_video_set_depth (sdlvid, VISUAL_VIDEO_DEPTH_32BIT); visual_video_set_dimension (sdlvid, screen->w, screen->h); visual_video_set_pitch (sdlvid, screen->pitch); visual_video_set_buffer (sdlvid, scrbuf); input = visual_input_new ("alsa"); visual_input_realize (input); while (1) { visual_input_run (input); visual_actor_run (actor, input->audio); /* place on screen */ visual_video_blit_overlay (sdlvid, video, 0, 0, FALSE); visual_video_set_palette (scalevid, visual_actor_get_palette (actor)); visual_video_scale (scalevid, video, VISUAL_VIDEO_SCALE_BILINEAR); visual_video_blit_overlay (sdlvid, scalevid, 256, 0, FALSE); sdl_draw_buf (); usleep (5000); while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_F11: sdl_fullscreen_toggle (); break; case SDLK_q: alpha -= 8; if (alpha < 0) alpha = 0; break; case SDLK_a: alpha += 8; if (alpha > 255) alpha = 255; break; case SDLK_ESCAPE: goto out; break; } break; case SDL_VIDEORESIZE: sdl_size_request (event.resize.w, event.resize.h); break; case SDL_QUIT: goto out; break; } } } out: SDL_Quit (); }