From 3a0fe9a2700596abe8e29f042ca967f57cc014d7 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 20 Dec 2011 13:55:44 +0000 Subject: initial show version --- src/globeLayer.cpp | 277 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+) create mode 100755 src/globeLayer.cpp (limited to 'src/globeLayer.cpp') diff --git a/src/globeLayer.cpp b/src/globeLayer.cpp new file mode 100755 index 0000000..17b1fec --- /dev/null +++ b/src/globeLayer.cpp @@ -0,0 +1,277 @@ +#include "globeLayer.h" +globeLayer::globeLayer() +{ + x=y=0.0f; + w=ofGetWindowWidth(); + h=ofGetWindowHeight(); + mixAmount=1.0f; +} +globeLayer::globeLayer(map * _settings) +{ + settings=map(*_settings); + x=ofToFloat(settings["x"]); + y=ofToFloat(settings["y"]); + w=ofToFloat(settings["w"]); + h=ofToFloat(settings["h"]); + note=ofToInt(settings["note"]); + mix=ofToInt(settings["mix"]); + if (mix>0) mixAmount=0.0f; + else mixAmount=1.0f; + active=false; + + printf("layer created, %fx%f\n",w,h); +} +void globeLayer::draw() { + if (mixAmount<1.0f) { + glEnable(GL_BLEND); + glBlendFunc(GL_CONSTANT_ALPHA,GL_ONE); + glBlendColor(1.0f,1.0f,1.0f, mixAmount); + } + else glDisable(GL_BLEND); +} +void globeLayer::update() { +} +void globeLayer::setActive(bool _active){ + active=_active; +} +/* +void globeLayer::setMixAmt(float _mixAmt){ + mixAmount=_mixAmt; +} +*/ +void globeLayer::CC(int _controller,int _value) { + if (_controller==mix) mixAmount=((float)_value)/127.0f; + //printf("layer: mix %f\n",mixAmount); +} + +//==================================================== + +globePlayer::globePlayer(map * _settings) +:globeLayer(_settings) +{ + fileName=settings["name"]; + if(player.loadMovie(fileName)) { + printf("globePlayer: loaded %s\n",fileName.c_str()); + player.setLoopState(OF_LOOP_NORMAL); + } + else printf("globePlayer: could not load %s\n",fileName.c_str()); + + isPlaying=false; +} +globePlayer::~globePlayer() +{ + +} +void globePlayer::CC(int _controller,int _value){ + globeLayer::CC(_controller,_value); +} + +void globePlayer::update() +{ + if (!isPlaying&&active) { + player.setFrame(0); + player.setSpeed(1.0f); + player.play(); + isPlaying=true; + } + if (isPlaying&&!active) { + player.stop(); + isPlaying=false; + } + if (active) player.idleMovie(); + +} +void globePlayer::draw() +{ + if (active) { + globeLayer::draw(); + player.draw(x,y,w,h); + } +} + +//==================================================== + +globeGrabber::globeGrabber(map * _settings) +:globeLayer(_settings) +{ + camWidth=ofToInt(settings["grabW"]); + camHeight=ofToInt(settings["grabH"]); + + //grabber.setVerbose(true); + grabber.listDevices(); + int device=ofToInt(settings["device"]); + if (device>0) { + //grabber.setDeviceID(device); + printf("using device %i\n",device); + } + grabber.initGrabber(camWidth,camHeight); + + deInterlace=ofToInt(settings["deInt"])!=0; + + outTexture.allocate(camWidth,camHeight, GL_RGB); + + gammamap=new unsigned char[256]; + line1=new unsigned char[camWidth]; + line2=new unsigned char[camWidth]; + outBuffer=new unsigned char[camWidth*camHeight*3]; + + whitePt=ofToFloat(settings["whitePoint"]); + blackPt=ofToFloat(settings["blackPoint"]); + gamma=ofToFloat(settings["gamma"]); + + whitePCtl=ofToInt(settings["whitePtCtl"]); + blackPCtl=ofToInt(settings["blackPtCtl"]); + gammaCtl=ofToInt(settings["gammaCtl"]); + devCtl=ofToInt(settings["devCtl"]); + + redCtl=ofToInt(settings["redCtl"]); + blueCtl=ofToInt(settings["blueCtl"]); + greenCtl=ofToInt(settings["greenCtl"]); + + calcGammaMap(); + + lineOffset=ofToInt("lineOffset"); + + field2=false; + use2fields=true; + + red=green=blue=1.0; + + + + flip=false; + flipCtl=ofToInt(settings["flipCtl"]); + + printf("grabber: RGB %f,%f,%f %f-%f-%f\n",red,green,blue,whitePt,blackPt,gamma); +} +globeGrabber::~globeGrabber() +{ +} +void globeGrabber::calcGammaMap(){ + for (int i=0;i<256;i++){ + //gammamap[i]=(unsigned char)(min(1.0f,pow(max(0.0f,(float(i)/180.0f)-0.4f),0.5f))*255.0); + + float ewp=max(whitePt,blackPt+0.1f); //limit range to 0.1 + gammamap[i]=(unsigned char)(pow(min(1.0f,max(0.0f,(((float(i)/255.0f)-blackPt)/(ewp-blackPt)))),gamma)*255.0); + } +} +unsigned char globeGrabber::gsGammaMap(unsigned char *pixel) { + return gammamap[(unsigned char)((((int(pixel[0])*76)+(int(pixel[1])*150)+(int(pixel[2]))*28))>>8)]; +} +void globeGrabber::CC(int _controller,int _value){ + globeLayer::CC(_controller,_value); + //add some colour settings + if (_controller==whitePCtl||_controller==blackPCtl||_controller==gammaCtl){ + if (_controller==whitePCtl) whitePt=((float)_value)/127.0; + if (_controller==blackPCtl) blackPt=((float)_value)/127.0; + if (_controller==gammaCtl) gamma=(((float)_value)/63.0)+0.1f; //0.1-2.1 + calcGammaMap(); + } + if (_controller==redCtl) red=((float)_value)/127.0; + if (_controller==blueCtl) blue=((float)_value)/127.0; + if (_controller==greenCtl) green=((float)_value)/127.0; + if (_controller==flipCtl) flip=_value>63; + if (_controller==devCtl) { + grabber.close(); + grabber.setDeviceID(_value); + grabber.initGrabber(camWidth,camHeight); + printf("Grabber changed to device %i\n",_value); + + } + + //printf("grabber: RGB %f,%f,%f %f-%f-%f\n",red,green,blue,blackPt,gamma,whitePt); +} +void globeGrabber::update() +{ + if (active) grabber.grabFrame(); + if (grabber.isFrameNew()){ + int time=ofGetElapsedTimeMillis(); + frameTime=time-grabTime; + grabTime=time; + unsigned char * pixels = grabber.getPixels(); + if(!deInterlace) { + int totalPixels = camWidth*camHeight; + for (int i = 0; i < totalPixels; i++){ + unsigned char gs=(unsigned char)((int(pixels[i*3])+int(pixels[i*3+1])+int(pixels[i*3+2]))/3); + outBuffer[i*3] = gammamap[gs]; + outBuffer[i*3+1] = gammamap[gs]; + outBuffer[i*3+2] = gammamap[gs]; + } + } + else { + field2=true; + unsigned char* lp1=line1; + unsigned char* lp2=line2; + unsigned char* tp; + int j = 0; + for (int i=0;i=(frameTime/2))){ + field2=false; + unsigned char * pixels = grabber.getPixels(); + unsigned char* lp1=line1; + unsigned char* lp2=line2; + unsigned char* tp; + int j = 1; + for (int i=0;i