From b79752f96f9e58c0b4636cc024add698e0ce0c5f Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 20 Aug 2013 14:49:48 +0100 Subject: frame mode for video loader + audio output bugfix --- rotord/src/libavwrapper.cpp | 2 +- rotord/src/rotor.cpp | 22 ++++++++++++++++------ rotord/src/rotor.h | 39 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp index 1b18769..6081ed6 100755 --- a/rotord/src/libavwrapper.cpp +++ b/rotord/src/libavwrapper.cpp @@ -1566,7 +1566,7 @@ bool libav::audioloader::setup(const std::string &filename){ return &packet; } - uint16_t* libav::audioloader::get_samples(int num){ //presumes 16bpc here + uint16_t* libav::audioloader::get_samples(int num){ //presumes 16bpc here and outputs interleaved samples //std::cerr << "request "<channels*audioloader.codecContext->sample_rate)/framerate; + string whether=usingaudio?"Loading":"Cannot load"; + logger.information(whether+" audio file: "+audio_filename+", each frame contains "+ofToString(samples_in_frame)+" samples at "+ofToString(audioloader.codecContext->sample_rate)+" hz"); + float vstep=1.0f/framerate; float v=0.0f; float vf=0.0f; @@ -302,7 +303,16 @@ Image* Video_loader::output(const Frame_spec &frame){ float clipspeed=(clipframerate/frame.framerate)*parameters["speed"]->value; - int wanted=(((int) ((frame.time*frame.framerate*clipspeed)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1? + int wanted; + if (attributes["mode"]->intVal==VIDEOFRAMES_frame) { + wanted=(((int) ((frame.time*frame.framerate)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1? + } + if (attributes["mode"]->intVal==VIDEOFRAMES_blend) { + wanted=(((int) ((frame.time*frame.framerate*clipspeed)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1? + } + + cerr<<"Video_loader: wanted frame "< _vals={}): description(_desc),title(_title),value(_value),intVal(0){ vals=_vals; + init(_value); }; void init(const string &_key){ //inits int value from set::string vals index value=_key; @@ -157,6 +158,14 @@ namespace Rotor { void create_attribute(const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector _vals={}) { attributes[_attr]=new Attribute(_desc,_title,_value,_vals); }; + void create_attribute(string *alias,const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector _vals={}) { + attributes[_attr]=new Attribute(_desc,_title,_value,_vals); + alias=&(attributes[_attr]->value); + }; + void create_attribute(int *alias,const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector _vals={}) { + attributes[_attr]=new Attribute(_desc,_title,_value,_vals); + alias=&(attributes[_attr]->intVal); + }; string description; string type; string ID; @@ -227,6 +236,29 @@ namespace Rotor { virtual void print_summary(){}; int channels,bits,samples,rate; }; + class LUT { + LUT(){ + lut=nullptr; + }; + ~LUT(){if (lut) { delete[] lut;} }; + void generate(float black_in,float white_in,float black_out,float white_out,float gamma){ + //can check here if anything has changed + if (lut) delete[] lut; + lut=new unsigned char[256]; + float fltmax=(255.0f/256.0f); + for (int i=0;i<256;i++){ + lut[i]=(unsigned char)(((pow(min(fltmax,max(0.0f,(((((float)i)/256.0f)-black_in)/(white_in-black_in)))),(1.0/gamma))*(white_out-black_out))+black_out)*255.0f); + } + } + void apply(const cv::Mat& in,cv::Mat &out){ //facility to apply to other images for inherited classes + out.create(in.rows,in.cols,in.type()); + for (int i=0;i