# HG changeset patch # User John Tsiombikas # Date 1318994612 -10800 # Node ID 7f7342bfbb25415287f87c02d6fd1ac9269d2ada vpost plugin for that video: http://www.youtube.com/watch?v=txt6SGL483E diff -r 000000000000 -r 7f7342bfbb25 hullsdr/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hullsdr/Makefile Wed Oct 19 06:23:32 2011 +0300 @@ -0,0 +1,14 @@ +obj = hullsdr_post.o +so = hullsdr_post.so + +CC = gcc +CFLAGS = -pedantic -Wall -g -fPIC +LDFLAGS = -limago -ldsys -ldrawtext -lGL -lGLU -lglut + +$(so): $(obj) + $(CC) -o $@ -shared $(obj) $(LDFLAGS) + + +.PHONY: clean +clean: + rm -f $(obj) $(so) diff -r 000000000000 -r 7f7342bfbb25 hullsdr/encode --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hullsdr/encode Wed Oct 19 06:23:32 2011 +0300 @@ -0,0 +1,6 @@ +#!/bin/sh + +ffmpeg -i output/frame%4d.png -vpre libvpx-720p -b 3900k -pass 1 -an -f webm -y output.webm + +ffmpeg -i output/frame%4d.png -vpre libvpx-720p -b 3900k -pass 2 -an -f webm -y output.webm +#ffmpeg -i output/frame%4d.png -vpre libvpx-720p -b 3900k -pass 2 -acodec libvorbis -ab 100k -f webm -y output.webm diff -r 000000000000 -r 7f7342bfbb25 hullsdr/hullsdr_post.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hullsdr/hullsdr_post.c Wed Oct 19 06:23:32 2011 +0300 @@ -0,0 +1,177 @@ +#include +#include +#include +#include +#include +#include +#include + +static void disp(void); +static void draw_text(void); +static void reshape(int x, int y); + +static struct img_pixmap *curfrm; +static int nfrm; +static int xsz = -1, ysz; +static float tsec; + +static struct dsys_demo *script; + +static struct dtx_font *font; + +static struct { + const char *name, *caption; + struct dsys_event *ev; +} events[] = { + {"diffuse", "diffuse only - 1 light", 0}, + {"diffuse2", "diffuse only - 2 lights", 0}, + {"vmanip", "vertex manipulation", 0}, + {"2tone", "two-tone paint", 0}, + {"specular2", "full phong - 2 lights", 0}, + {"celshade", "cel shading", 0}, + {"sphmap", "reflection - spherical env. map", 0}, + {"cubemap", "reflection - cubic env. map", 0}, + {"refract", "relfection & refraction - cubic env. map w/fresnel", 0}, + {"distort1", "image distortion", 0}, + {"blur", "blur", 0}, + {"distort2", "image distortion (again)", 0}, + {0, 0, 0} +}; + + +int init(void) +{ + int i, argc = 1; + char *argv[] = {"./vpost", 0}; + + if(!(font = dtx_open_font("linux-libertine.ttf", 32))) { + fprintf(stderr, "failed to open font\n"); + return -1; + } + + if(!(script = dsys_open("script"))) { + fprintf(stderr, "failed to open script\n"); + return -1; + } + + for(i=0; events[i].name; i++) { + events[i].ev = dsys_event(script, events[i].name); + } + + glutInit(&argc, argv); + glutInitWindowSize(32, 32); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + + glutCreateWindow("foo"); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glutDisplayFunc(disp); + glutReshapeFunc(reshape); + return 0; +} + +void shutdown(void) +{ + printf("shutdown called\n"); +} + +int process(struct img_pixmap *frame, int frm_num, float sec) +{ + curfrm = frame; + nfrm = frm_num; + tsec = sec; + + if(frame->width != xsz || frame->height != ysz) { + glutReshapeWindow(frame->width, frame->height); + } + glutPostRedisplay(); + + while(curfrm) { + glutMainLoopEvent(); + } + return 0; +} + +static void disp(void) +{ + assert(curfrm); + glClear(GL_COLOR_BUFFER_BIT); + + dsys_update(script, dsys_msec_to_dtime(nfrm)); + + glDrawPixels(xsz, ysz, GL_RGB, GL_UNSIGNED_BYTE, curfrm->pixels); + + draw_text(); + + glFlush(); + glReadPixels(0, 0, xsz, ysz, GL_RGB, GL_UNSIGNED_BYTE, curfrm->pixels); + + glutSwapBuffers(); + curfrm = 0; + + assert(glGetError() == GL_NO_ERROR); +} + +static float fade(float x) +{ + x = 1.0 - (cos((x) * M_PI * 2.0) * 0.5 + 0.5); + x *= 10.0f; + + return x > 1.0 ? 1.0 : x; +} + +static void caption(const char *text, struct dsys_event *ev) +{ + float t = fade(dsys_event_value(ev)); + + if(t < (1.0f / 255.0f)) { + return; + } + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslatef(0, 40 * t - 20, 0); + + glBegin(GL_QUADS); + glColor4f(0.7, 0.2, 0.1, t); + glVertex2f(0, -10); + glVertex2f(xsz, -10); + glVertex2f(xsz, 30); + glVertex2f(0, 30); + glEnd(); + + glTranslatef(20, 0, 0); + + glColor4f(1, 1, 1, t); + dtx_string(text); + + glPopMatrix(); +} + + +static void draw_text(void) +{ + int i; + dtx_use_font(font, 32); + + glPushAttrib(GL_ENABLE_BIT); + glEnable(GL_BLEND); + + for(i=0; events[i].name; i++) { + caption(events[i].caption, events[i].ev); + } + + glPopAttrib(); +} + +static void reshape(int x, int y) +{ + xsz = x; + ysz = y; + + glViewport(0, 0, x, y); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, x, y, 0, -1, 1); +} diff -r 000000000000 -r 7f7342bfbb25 hullsdr/script --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hullsdr/script Wed Oct 19 06:23:32 2011 +0300 @@ -0,0 +1,12 @@ +0 341 diffuse +342 667 diffuse2 +668 845 vmanip +846 1412 2tone +1413 1933 specular2 +1934 2451 celshade +2452 2763 sphmap +2764 3538 cubemap +3539 4666 refract +4667 5525 distort1 +5526 5610 blur +5611 5954 distort2 diff -r 000000000000 -r 7f7342bfbb25 hullsdr/test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hullsdr/test Wed Oct 19 06:23:32 2011 +0300 @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -f output/frame*.png +vpost -p ./hullsdr_post.so -i input/frame%04d.png -o output/frame%04d.png