Esempio n. 1
0
void setAnimation(Animation * a, int loopAnimation) {     //////loopAnimation=-1 (no repeat)  0 (repeat) >0 (wait and repeat)
  animation = a;
  framePointer = 0;
  pwmCounter = 0;
  linePointer = 0;
  memcpy_P(&currentFrame, &(animation->frames[framePointer]), sizeof(Frame));
  _prepareFrame();
  oriRepeat = repeat = loopAnimation;

}
Esempio n. 2
0
void updateFrame() {
  unsigned long t = millis();
  if(running && t - frameStartTime > currentFrame.frameTime) {
    // Preapre the next frame
    framePointer ++;
    if(framePointer >= animation->frameCount) {
      if(repeat == 0) { ///loop back to frame0
        framePointer = 0;
        //repeat = 0;
        if (oriRepeat==0) repeat=0;
        else repeat=1+rand()%oriRepeat;
      } else if (repeat>0) { ///wait and then loop
        repeat--;
        framePointer = animation->frameCount - 1;
      } else { ///repeat<0 (no repeat)
        framePointer = animation->frameCount - 1;
      }
    }
    memcpy_P(&currentFrame, &(animation->frames[framePointer]), sizeof(Frame));
    _prepareFrame();
    frameStartTime = t;
  }
}
Esempio n. 3
0
void DGVideo::update() {
    if (_state == DGVideoPlaying) {
        time_t currentTime = DGSystem::getInstance().wallTime();
        double duration = (double)(currentTime - _lastTime) / CLOCKS_PER_SEC;
        
        if (duration >= _frameDuration) {
            yuv_buffer yuv;
            
            // TODO: Skip frames if required here?
            //int frames = (int)floor(duration / _frameDuration);
            //for (int i = 1; i <= frames; i++)
                _prepareFrame();
            
            theora_decode_YUVout(&_theoraInfo->td, &yuv);
            _convertToRGB(yuv.y, yuv.y_stride,
                       yuv.u, yuv.v, yuv.uv_stride,
                       _currentFrame.data, _theoraInfo->ti.width, _theoraInfo->ti.height, _theoraInfo->ti.width);
            
            _lastTime = currentTime;
            
            _hasNewFrame = true;
        }
	}
}