| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -6,58 +6,66 @@ Player::Player(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/* Basic ofVideoPlayer setup */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Player::Setup(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    videoPlayer.setLoopState(OF_LOOP_NONE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    videoPlayer.setLoopState(OF_LOOP_NORMAL); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    videoPlayer.setVolume(0); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/* Updated the video player:
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    (1) Allocates the required W x H for the model input | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    (2) Updates the video texture, and sets the current frame value */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Player::Update(ofImage &img){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Player::Update(ofImage &img, bool show_frame){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(!img.isAllocated()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        img.allocate(ofGetWindowWidth() / 2, ofGetWindowHeight(), OF_IMAGE_COLOR); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        temp.allocate(ofGetWindowWidth() / 2, ofGetWindowHeight(), GL_RGB); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(videoPlayer.isLoaded()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        hasVideo = true; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        playerCurrentFrame = videoPlayer.getCurrentFrame(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        videoPlayer.update(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        videoPlayer.play(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // Calculate the target width and height for model_output_fbo_1
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    float fbo_1_target_width = img.getWidth();  // 1/2 of the screen width (990px)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    float fbo_1_target_height = img.getHeight();  // Full height of the screen
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // Calculate the aspect ratio of the video and the FBO
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        float video_aspect_ratio = videoPlayer.getWidth() / videoPlayer.getHeight(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    float fbo_aspect_ratio = fbo_1_target_width / fbo_1_target_height; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    float aspect_ratio; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(show_frame && frame.isAllocated()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        aspect_ratio = frame.getWidth() / frame.getHeight(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    }  | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // Adjust the scaling to cover the FBO area while maintaining aspect ratio
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(videoPlayer.isLoaded() && !show_frame){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        hasVideo = true; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        playerCurrentFrame = videoPlayer.getCurrentFrame(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        videoPlayer.update(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        aspect_ratio = videoPlayer.getWidth() / videoPlayer.getHeight(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (fbo_aspect_ratio > video_aspect_ratio) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if (fbo_aspect_ratio > aspect_ratio) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // FBO is wider; scale by width to fill the FBO
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        new_width = fbo_1_target_width; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            new_height = new_width / video_aspect_ratio;  // Scale height to maintain aspect ratio
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        new_height = new_width / aspect_ratio;  // Scale height to maintain aspect ratio
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // FBO is taller; scale by height to fill the FBO
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        new_height = fbo_1_target_height; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            new_width = new_height * video_aspect_ratio;  // Scale width to maintain aspect ratio
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        new_width = new_height * aspect_ratio;  // Scale width to maintain aspect ratio
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    // Center the video to ensure it fills the FBO and is cropped if necessary
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    x_pos = (ofGetWindowWidth() * 0.25) - (new_width / 2); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    y_pos = (ofGetWindowHeight() - new_height) / 2;  // Center vertically
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(show_frame && frame.isAllocated()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        temp.begin(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        frame.draw(x_pos, y_pos, new_width, new_height); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        temp.end(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    }  | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(videoPlayer.isLoaded() && !show_frame){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        temp.begin(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        videoPlayer.draw(x_pos, y_pos, new_width, new_height); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        temp.end(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ofPixels pixels; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    temp.readToPixels(pixels); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    img.setFromPixels(pixels); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Player::Draw(){ | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -75,10 +83,16 @@ ofPixels Player::GetVideoPixels(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    (2) Allocates the fbo dims for final render */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Player::SetVideo(std::string path, ofFbo &fbo){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    videoPlayer.load(path); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    videoPlayer.play(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    videoPlayer.setFrame(800); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    fbo.allocate(ofGetWindowWidth() / 2, ofGetWindowHeight(), GL_RGB); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					/* Loads a frame from path */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Player::SetFrame(std::string path){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    frame.load(path); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					// Sets a random frame in the active video
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void Player::SetRandomFrame(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    int randomFrame = ofRandom(0, videoPlayer.getTotalNumFrames()); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |