int render_metaballs(float time, float ltime) { int obj = 0; float dist1 = 128 + sinf(time * M_PI * 1.0 * 0.8 * 0.4 + 0) * 95; float dist2 = 128 + sinf(time * M_PI * 1.2 * 0.8 * 0.4 + 1) * 95; float dist3 = 130 + sinf(time * M_PI * 1.3 * 0.8 * 0.4 + 2) * 95; float dist4 = 100 + sinf(time * M_PI * 1.4 * 0.8 * 0.4 + 3) * 95; float dist5 = 128 + sinf(time * M_PI * 1.5 * 0.5 * 0.4 + 4) * 95; float dist6 = 128 + sinf(time * M_PI * 1.6 * 0.5 * 0.4 + 5) * 95; float dist7 = 130 + sinf(time * M_PI * 1.7 * 0.5 * 0.4 + 6) * 95; float dist8 = 100 + sinf(time * M_PI * 1.8 * 0.5 * 0.4 + 7) * 95; if (time < 1.0) dist1 -= 256-256*sinf((time) * M_PI / 2); if (time < 3.0) dist2 += 256-256*sinf((time-2.0) * M_PI / 2); if (time < 5.0) { dist7 -= 256-256*sinf((time-4.0) * M_PI / 2); dist3 += 256-256*sinf((time-4.0) * M_PI / 2); } if (time < 7.0) { dist8 -= 256-256*sinf((time-6.0) * M_PI / 2); dist4 -= 256-256*sinf((time-6.0) * M_PI / 2); } if (ltime < 7.0) dist1 -= 256-256*sinf((ltime-6.0) * M_PI / 2); if (ltime < 5.0) dist2 += 256-256*sinf((ltime-4.0) * M_PI / 2); if (ltime < 3.0) { dist7 -= 256-256*sinf((ltime-2.0) * M_PI / 2); dist3 += 256-256*sinf((ltime-2.0) * M_PI / 2); } if (ltime < 1.0) { dist8 -= 256-256*sinf((ltime) * M_PI / 2); dist4 -= 256-256*sinf((ltime) * M_PI / 2); } memset(mbuf, 0, sizeof mbuf); if (ltime > 6.0) draw_metaball(dist1, dist5, 45); if (time > 2.0 && ltime > 4.0) draw_metaball(dist2, dist6, 10); if (time > 4.0 && ltime > 2.0) draw_metaball(dist7, dist3, 30); if (time > 6.0) draw_metaball(dist8, dist4, 70); olPushMatrix(); olTranslate(-1.0f, -1.0f); olScale(2.0f/256.0f, 2.0f/256.0f); //printf("%d %d\n", mbuf[0][0], mbuf[128][128]); obj = trace(&mbuf[0][0], &mtmp[0][0], 20000, 256, 256, 1); olPopMatrix(); return obj; }
void openlase_initialize(t_jit_openlase_trace *x, int width, int height) { if (x->initialized) { return; } //object_post((t_object *)x, "openlase_initialize enter"); if(olInit(FRAMES_BUF, 300000) < 0) { object_post((t_object *)x, "failed to initialize OpenLase"); return; } float overscan = x->overscan; float aspect = x->aspect; float snap_pix = x->snap_pix; //float framerate = 30; x->tparams.mode = OL_TRACE_THRESHOLD; x->tparams.sigma = 0; x->tparams.threshold2 = 50; //x->tparams.mode = OL_TRACE_CANNY; x->tparams.sigma = 1; if (aspect == 0) aspect = (float)width / height; // if (framerate == 0) // framerate = (float)pFormatCtx->streams[videoStream]->r_frame_rate.num / (float)pFormatCtx->streams[videoStream]->r_frame_rate.den; float iaspect = 1/aspect; if (aspect > 1) { olSetScissor(-1, -iaspect, 1, iaspect); olScale(1, iaspect); } else { olSetScissor(-aspect, -1, aspect, 1); olScale(aspect, 1); } olScale(1+overscan, 1+overscan); olTranslate(-1.0f, 1.0f); olScale(2.0f/width, -2.0f/height); int maxd = width > height ? width : height; x->params.snap = (snap_pix*2.0)/(float)maxd; //float frametime = 1.0f/framerate; olSetRenderParams(&x->params); x->tparams.width = width, x->tparams.height = height, olTraceInit(&x->trace_ctx, &x->tparams); //object_post((t_object *)x, "openlase initialized"); x->initialized = true; }
void render_fire(float left) { int x,y,i; int w = 256; int h = 256; for(i=0; i<2; i++) { int *p = &mbuf[h-1][0]; for (x=0;x<256;x++) { if (left > 0.7 && (random() % 100) > 60) *p++ = 1024; else *p++ = 0; } if (left > 2.0 && random() % 32 == 0) mbuf[h-1][random()%w] = random()%120000; for (y=254;y>=0;y--) { p = &mbuf[y][0]; *p++ = 0; for (x=1;x<255;x++) { *p = (*p + p[w-1] + p[w] + p[w+1]) / 4; if (*p) (*p)--; p++; } *p++ = 0; } } olPushMatrix(); olScale(1, -1); olTranslate(-1.0f, -1.0f); olScale(2.0f/256.0f, 2.0f/256.0f); olPushColor(); olMultColor(C_RED+C_GREEN_I(150)); trace(&mbuf[0][0], &mtmp[0][0], 200, 256, 235, 2); olPopColor(); olPushColor(); olMultColor(C_RED+C_GREEN_I(100)); trace(&mbuf[0][0], &mtmp[0][0], 250, 256, 235, 2); olPopColor(); olPushColor(); olMultColor(C_RED+C_GREEN_I(50)); trace(&mbuf[0][0], &mtmp[0][0], 300, 256, 235, 2); olPopColor(); olPushColor(); olMultColor(C_RED+C_GREEN_I(0)); trace(&mbuf[0][0], &mtmp[0][0], 400, 256, 235, 2); olPopColor(); olPopMatrix(); }
void DoCubes(float limit) { float ctime = 0; params.on_speed = 2.0/90.0; params.off_speed = 2.0/30.0; params.start_wait = 8; params.start_dwell = 6; params.curve_dwell = 0; params.corner_dwell = 8; params.end_dwell = 6; params.end_wait = 2; params.render_flags |= RENDER_NOREORDER; olSetRenderParams(¶ms); float xpos = -2.0; while(audiotime < limit) { if (ctime*AB < 1.5) xpos = -2.0 +2*sinf(ctime*AB * M_PI * 0.5 / 1.5); else if (audiotime > (limit-1.5)) xpos = 2-2*sinf((limit-audiotime) * M_PI * 0.5 / 1.5); else xpos = 0; olLoadIdentity(); olTranslate(xpos, 0); render_cubes(ctime*AB); olSetPixelShader(hfade); ctime -= 15.0; olDrawString(font, -1.2*(ctime-1.0), 0.35, 0.3, C_WHITE, "Spontz"); olDrawString(font, -1.5*(ctime-2.0), -0.60, 0.3, C_WHITE, "BiXo"); olDrawString(font, -1.3*(ctime-3.0), 0.70, 0.3, C_WHITE, "Xplsv"); olDrawString(font, -1.7*(ctime-4.0), 0.40, 0.3, C_WHITE, "Software Failure"); olDrawString(font, -1.4*(ctime-5.0), -0.75, 0.3, C_WHITE, "Nocturns"); olDrawString(font, -1.2*(ctime-6.0), -0.45, 0.3, C_WHITE, "Purple Studios"); olDrawString(font, -1.7*(ctime-7.0), 0.35, 0.3, C_WHITE, "Masca Team"); olDrawString(font, -1.2*(ctime-8.0), 0.60, 0.3, C_WHITE, "Glenz"); olDrawString(font, -1.3*(ctime-9.0), -0.40, 0.3, C_WHITE, "Napalm Core"); olDrawString(font, -1.5*(ctime-10.0), -0.75, 0.3, C_WHITE, "TDA"); olDrawString(font, -1.3*(ctime-11.0), 0.45, 0.3, C_WHITE, "ASD"); ctime += 15.0; olSetPixelShader(NULL); ctime += render(); } }
void circle(float x, float y, float r, uint32_t color) { olPushMatrix(); olPushColor(); olMultColor(color); olTranslate(x, y); olRotate((x+y)*123); /*olBegin(OL_BEZIERSTRIP); olVertex(0, r, color); int i; for (i=0; i<2; i++) { olVertex(CP*r, r, C_WHITE); olVertex(r, CP*r, C_WHITE); olVertex(r, 0, C_WHITE); olVertex(r, -CP*r, C_WHITE); olVertex(CP*r, -r, C_WHITE); olVertex(0, -r, C_WHITE); olVertex(-CP*r, -r, C_WHITE); olVertex(-r, -CP*r, C_WHITE); olVertex(-r, 0, C_WHITE); olVertex(-r, CP*r, C_WHITE); olVertex(-CP*r, r, C_WHITE); olVertex(0, r, C_WHITE); }*/ /* olVertex(0, r, color); olVertex(0, r, color); olVertex(r*0.1, r, color); olVertex(r*0.1, r, color);*/ float circum = 2 * M_PI * r; int segments = circum / (1/30.0); if (segments < 50) segments = 50; int i; olBegin(OL_POINTS); olVertex(r, 0); for (i=0; i<=(2*segments+10); i++) { float w = i * M_PI * 2.0 / segments; uint32_t c = C_WHITE; if (i > 2*segments) c = C_GREY((10-(i-segments)) * 28); else if (i < 3) c = C_GREY(i * 85); olVertex(r*cosf(w), r*sinf(w)); } olEnd(); olPopColor(); olPopMatrix(); }
int main (int argc, char *argv[]) { OLRenderParams params; AVFrame *frame; int i; // Register all formats and codecs av_register_all(); memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/15.0; params.start_wait = 8; params.end_wait = 3; params.snap = 1/120.0; params.render_flags = RENDER_GRAYSCALE; params.min_length = 4; params.start_dwell = 2; params.end_dwell = 2; float snap_pix = 3; float aspect = 0; float framerate = 0; float overscan = 0; int thresh_dark = 60; int thresh_light = 160; int sw_dark = 100; int sw_light = 256; int decimate = 2; int edge_off = 0; int optchar; OLTraceParams tparams = { .mode = OL_TRACE_THRESHOLD, .sigma = 0, .threshold2 = 50 }; while ((optchar = getopt(argc, argv, "hct:T:b:w:B:W:O:d:m:S:E:D:g:s:p:a:r:R:o:v:")) != -1) { switch (optchar) { case 'h': case '?': usage(argv[0]); return 0; case 'c': tparams.mode = OL_TRACE_CANNY; tparams.sigma = 1; break; case 't': thresh_dark = thresh_light = atoi(optarg); break; case 'T': tparams.threshold2 = atoi(optarg); break; case 'b': thresh_dark = atoi(optarg); break; case 'w': thresh_light = atoi(optarg); break; case 'B': sw_dark = atoi(optarg); break; case 'W': sw_light = atoi(optarg); break; case 'O': edge_off = atoi(optarg); break; case 'd': decimate = atoi(optarg); break; case 'm': params.min_length = atoi(optarg); break; case 'S': params.start_wait = atoi(optarg); break; case 'E': params.end_wait = atoi(optarg); break; case 'D': params.start_dwell = atoi(optarg); params.end_dwell = atoi(optarg); break; case 'g': tparams.sigma = atof(optarg); break; case 's': params.off_speed = 2.0f/atof(optarg); break; case 'p': snap_pix = atof(optarg); break; case 'a': aspect = atof(optarg); break; case 'r': framerate = atof(optarg); break; case 'R': params.max_framelen = params.rate/atof(optarg); break; case 'o': overscan = atof(optarg); break; case 'v': volume = atof(optarg); break; } } if (optind == argc) { usage(argv[0]); return 1; } if (av_vid_init(argv[optind]) != 0) { printf("Video open/init failed\n"); return 1; } if (av_aud_init(argv[optind]) != 0) { printf("Audio open/init failed\n"); return 1; } if(olInit(FRAMES_BUF, 300000) < 0) { printf("OpenLase init failed\n"); return 1; } if (aspect == 0) aspect = pCodecCtx->width / (float)pCodecCtx->height; if (framerate == 0) framerate = (float)pFormatCtx->streams[videoStream]->r_frame_rate.num / (float)pFormatCtx->streams[videoStream]->r_frame_rate.den; float iaspect = 1/aspect; if (aspect > 1) { olSetScissor(-1, -iaspect, 1, iaspect); olScale(1, iaspect); } else { olSetScissor(-aspect, -1, aspect, 1); olScale(aspect, 1); } printf("Aspect is %f %f\n", aspect, iaspect); printf("Overscan is %f\n", overscan); olScale(1+overscan, 1+overscan); olTranslate(-1.0f, 1.0f); olScale(2.0f/pCodecCtx->width, -2.0f/pCodecCtx->height); int maxd = pCodecCtx->width > pCodecCtx->height ? pCodecCtx->width : pCodecCtx->height; params.snap = (snap_pix*2.0)/(float)maxd; float frametime = 1.0f/framerate; printf("Framerate: %f (%fs per frame)\n", framerate, frametime); olSetAudioCallback(moreaudio); olSetRenderParams(¶ms); float vidtime = 0; int inf=0; int bg_white = -1; float time = 0; float ftime; int frames = 0; OLFrameInfo info; OLTraceCtx *trace_ctx; OLTraceResult result; memset(&result, 0, sizeof(result)); tparams.width = pCodecCtx->width, tparams.height = pCodecCtx->height, olTraceInit(&trace_ctx, &tparams); while(GetNextFrame(pFormatCtx, pCodecCtx, videoStream, &frame)) { if (inf == 0) printf("Frame stride: %d\n", frame->linesize[0]); inf+=1; if (vidtime < time) { vidtime += frametime; printf("Frame skip!\n"); continue; } vidtime += frametime; int thresh; int obj; int bsum = 0; int c; for (c=edge_off; c<(pCodecCtx->width-edge_off); c++) { bsum += frame->data[0][c+edge_off*frame->linesize[0]]; bsum += frame->data[0][c+(pCodecCtx->height-edge_off-1)*frame->linesize[0]]; } for (c=edge_off; c<(pCodecCtx->height-edge_off); c++) { bsum += frame->data[0][edge_off+c*frame->linesize[0]]; bsum += frame->data[0][(c+1)*frame->linesize[0]-1-edge_off]; } bsum /= (2*(pCodecCtx->width+pCodecCtx->height)); if (bg_white == -1) bg_white = bsum > 128; if (bg_white && bsum < sw_dark) bg_white = 0; if (!bg_white && bsum > sw_light) bg_white = 1; if (bg_white) thresh = thresh_light; else thresh = thresh_dark; tparams.threshold = thresh; olTraceReInit(trace_ctx, &tparams); olTraceFree(&result); obj = olTrace(trace_ctx, frame->data[0], frame->linesize[0], &result); do { int i, j; for (i = 0; i < result.count; i++) { OLTraceObject *o = &result.objects[i]; olBegin(OL_POINTS); OLTracePoint *p = o->points; for (j = 0; j < o->count; j++) { if (j % decimate == 0) olVertex(p->x, p->y, C_WHITE); p++; } olEnd(); } ftime = olRenderFrame(200); olGetFrameInfo(&info); frames++; time += ftime; printf("Frame time: %.04f, Cur FPS:%6.02f, Avg FPS:%6.02f, Drift: %7.4f, " "In %4d, Out %4d Thr %3d Bg %3d Pts %4d", ftime, 1/ftime, frames/time, time-vidtime, inf, frames, thresh, bsum, info.points); if (info.resampled_points) printf(" Rp %4d Bp %4d", info.resampled_points, info.resampled_blacks); if (info.padding_points) printf(" Pad %4d", info.padding_points); printf("\n"); } while ((time+frametime) < vidtime); } olTraceDeinit(trace_ctx); for(i=0;i<FRAMES_BUF;i++) olRenderFrame(200); olShutdown(); av_deinit(); exit (0); }
static VALUE ol_translate(VALUE self, VALUE x, VALUE y) { olTranslate(NUM2DBL(x), NUM2DBL(y)); return Qnil; }
void *display_thread(void *arg) { PlayerCtx *ctx = arg; int i; OLRenderParams params; memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/100.0; params.off_speed = 2.0/15.0; params.start_wait = 8; params.end_wait = 3; params.snap = 1/120.0; params.render_flags = RENDER_GRAYSCALE; params.min_length = 20; params.start_dwell = 2; params.end_dwell = 2; params.max_framelen = 48000/20.0; if(olInit(OL_FRAMES_BUF, 300000) < 0) { printf("OpenLase init failed\n"); return NULL; } float aspect = ctx->width / (float)ctx->height; float sample_aspect = av_q2d(ctx->v_stream->sample_aspect_ratio); if (sample_aspect != 0) aspect *= sample_aspect; printf("Aspect: %f\n", aspect); float iaspect = 1/aspect; int maxd = ctx->width > ctx->height ? ctx->width : ctx->height; int mind = ctx->width < ctx->height ? ctx->width : ctx->height; g_ctx = ctx; olSetAudioCallback(get_audio); olSetRenderParams(¶ms); OLTraceCtx *trace_ctx; OLTraceParams tparams; OLTraceResult result; memset(&result, 0, sizeof(result)); ctx->settings_changed = 1; tparams.sigma = ctx->settings.blur / 100.0; if (ctx->settings.canny) tparams.mode = OL_TRACE_CANNY; else tparams.mode = OL_TRACE_THRESHOLD; tparams.width = ctx->width; tparams.height = ctx->height; printf("Resolution: %dx%d\n", ctx->width, ctx->height); olTraceInit(&trace_ctx, &tparams); VideoFrame *last = NULL; pthread_mutex_lock(&ctx->display_mode_mutex); DisplayMode display_mode = ctx->display_mode; pthread_mutex_unlock(&ctx->display_mode_mutex); int inf = 0; int bg_white = -1; float time = 0; int frames = 0; while (display_mode != STOP) { pthread_mutex_lock(&ctx->settings_mutex); PlayerSettings settings = ctx->settings; int settings_changed = ctx->settings_changed; ctx->settings_changed = 0; pthread_mutex_unlock(&ctx->settings_mutex); if (ctx->audio_idx == -1) { drop_all_video(ctx); next_video_frame(ctx); } params.min_length = settings.minsize; params.end_dwell = params.start_dwell = settings.dwell; params.off_speed = settings.offspeed * 0.002; params.snap = (settings.snap*2.0)/(float)maxd; params.start_wait = settings.startwait; params.end_wait = settings.endwait; if (settings.minrate == 0) params.max_framelen = 0; else params.max_framelen = params.rate / settings.minrate; olSetRenderParams(¶ms); olLoadIdentity(); if (aspect > 1) { olSetScissor(-1, -iaspect, 1, iaspect); olScale(1, iaspect); } else { olSetScissor(-aspect, -1, aspect, 1); olScale(aspect, 1); } olScale(1 + settings.overscan/100.0, 1 + settings.overscan/100.0); olTranslate(-1.0f, 1.0f); olScale(2.0f/ctx->width, -2.0f/ctx->height); if (!ctx->cur_frame || ctx->cur_frame->seekid < 0) { printf("Dummy frame\n"); float ftime = olRenderFrame(80); pthread_mutex_lock(&ctx->display_mode_mutex); display_mode = ctx->display_mode; pthread_mutex_unlock(&ctx->display_mode_mutex); if (ctx->cur_frame && ctx->cur_frame->seekid < 0) deliver_event(ctx, time, ftime, frames, 1); else deliver_event(ctx, time, ftime, frames, 0); continue; } if (last != ctx->cur_frame || settings_changed) { tparams.sigma = settings.blur / 100.0; if (settings.canny) { tparams.mode = OL_TRACE_CANNY; tparams.threshold = settings.threshold; tparams.threshold2 = settings.threshold2; bg_white = -1; } else { tparams.mode = OL_TRACE_THRESHOLD; if (settings.splitthreshold) { int edge_off = mind * settings.offset / 100; int bsum = 0; int cnt = 0; int c; for (c = edge_off; c < (ctx->width-edge_off); c++) { bsum += ctx->cur_frame->data[c+edge_off*ctx->cur_frame->stride]; bsum += ctx->cur_frame->data[c+(ctx->height-edge_off-1)*ctx->cur_frame->stride]; cnt += 2; } for (c = edge_off; c < (ctx->height-edge_off); c++) { bsum += ctx->cur_frame->data[edge_off+ctx->cur_frame->stride]; bsum += ctx->cur_frame->data[(c+1)*ctx->cur_frame->stride-1-edge_off]; cnt += 2; } bsum /= cnt; if (bg_white == -1) bg_white = bsum > ((settings.darkval + settings.lightval)/2); if (bg_white && bsum < settings.darkval) bg_white = 0; if (!bg_white && bsum > settings.lightval) bg_white = 1; if (bg_white) tparams.threshold = settings.threshold2; else tparams.threshold = settings.threshold; } else { tparams.threshold = settings.threshold; } } olTraceReInit(trace_ctx, &tparams); olTraceFree(&result); printf("Trace\n"); olTrace(trace_ctx, ctx->cur_frame->data, ctx->cur_frame->stride, &result); printf("Trace done\n"); inf++; last = ctx->cur_frame; } int i, j; for (i = 0; i < result.count; i++) { OLTraceObject *o = &result.objects[i]; olBegin(OL_POINTS); OLTracePoint *p = o->points; for (j = 0; j < o->count; j++) { if (j % settings.decimation == 0) olVertex(p->x, p->y, C_WHITE); p++; } olEnd(); } float ftime = olRenderFrame(80); OLFrameInfo info; olGetFrameInfo(&info); frames++; time += ftime; printf("Frame time: %.04f, Cur FPS:%6.02f, Avg FPS:%6.02f, Drift: %7.4f, " "In %4d, Out %4d Thr %3d/%3d Bg %3d Pts %4d", ftime, 1/ftime, frames/time, 0.0, inf, frames, tparams.threshold, tparams.threshold2, 0, info.points); if (info.resampled_points) printf(" Rp %4d Bp %4d", info.resampled_points, info.resampled_blacks); if (info.padding_points) printf(" Pad %4d", info.padding_points); printf("\n"); deliver_event(ctx, time, ftime, frames, 0); pthread_mutex_lock(&ctx->display_mode_mutex); display_mode = ctx->display_mode; pthread_mutex_unlock(&ctx->display_mode_mutex); } olTraceDeinit(trace_ctx); for(i = 0; i < OL_FRAMES_BUF; i++) olRenderFrame(80); olShutdown(); return NULL; }