本文整理汇总了C++中video::VideoDecoder::needsUpdate方法的典型用法代码示例。如果您正苦于以下问题:C++ VideoDecoder::needsUpdate方法的具体用法?C++ VideoDecoder::needsUpdate怎么用?C++ VideoDecoder::needsUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类video::VideoDecoder
的用法示例。
在下文中一共展示了VideoDecoder::needsUpdate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: playVideo
void PrinceEngine::playVideo(Common::String videoFilename) {
// Set the correct video mode
initGraphics(640, 480, true, 0);
if (_system->getScreenFormat().bytesPerPixel == 1) {
warning("Couldn't switch to a RGB color video mode to play a video.");
return;
}
debug(2, "Screen format: %s", _system->getScreenFormat().toString().c_str());
Video::VideoDecoder *videoDecoder = new Video::AVIDecoder();
if (!videoDecoder->loadFile(videoFilename)) {
delete videoDecoder;
warning("Unable to open video %s", videoFilename.c_str());
initGraphics(640, 480, true);
return;
}
videoDecoder->start();
bool skipVideo = false;
while (!shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) {
if (videoDecoder->needsUpdate()) {
const Graphics::Surface *frame = videoDecoder->decodeNextFrame();
if (frame) {
if (frame->format.bytesPerPixel > 1) {
Graphics::Surface *frame1 = frame->convertTo(_system->getScreenFormat());
_system->copyRectToScreen(frame1->getPixels(), frame1->pitch, 0, 0, frame1->w, frame1->h);
frame1->free();
delete frame1;
} else {
_system->copyRectToScreen(frame->getPixels(), frame->pitch, 0, 0, frame->w, frame->h);
}
_system->updateScreen();
}
}
Common::Event event;
while (_system->getEventManager()->pollEvent(event)) {
if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) ||
event.type == Common::EVENT_LBUTTONUP)
skipVideo = true;
}
_system->delayMillis(10);
}
delete videoDecoder;
initGraphics(640, 480, true);
}
示例2: updateMovies
bool VideoManager::updateMovies() {
bool updateScreen = false;
for (VideoList::iterator it = _videos.begin(); it != _videos.end(); ) {
// Check of the video has reached the end
if ((*it)->endOfVideo()) {
if ((*it)->isLooping()) {
// Seek back if looping
(*it)->seek((*it)->getStart());
} else {
// Done; close and continue on
(*it)->close();
it = _videos.erase(it);
continue;
}
}
Video::VideoDecoder *video = (*it)->_video;
// Ignore paused videos
if (video->isPaused()) {
it++;
continue;
}
// Check if we need to draw a frame
if (video->needsUpdate()) {
if (drawNextFrame(*it)) {
updateScreen = true;
}
}
// Remember to increase the iterator
it++;
}
// Return true if we need to update the screen
return updateScreen;
}
示例3: playVideo
void ZVision::playVideo(Video::VideoDecoder &vid, const Common::Rect &destRect, bool skippable, Subtitle *sub) {
Common::Rect dst = destRect;
// If destRect is empty, no specific scaling was requested. However, we may choose to do scaling anyway
if (dst.isEmpty())
dst = Common::Rect(vid.getWidth(), vid.getHeight());
Graphics::Surface scaled;
if (vid.getWidth() != dst.width() || vid.getHeight() != dst.height())
scaled.create(dst.width(), dst.height(), vid.getPixelFormat());
uint16 x = _workingWindow.left + dst.left;
uint16 y = _workingWindow.top + dst.top;
uint16 finalWidth = dst.width() < _workingWindow.width() ? dst.width() : _workingWindow.width();
uint16 finalHeight = dst.height() < _workingWindow.height() ? dst.height() : _workingWindow.height();
bool showSubs = (_scriptManager->getStateValue(StateKey_Subtitles) == 1);
_clock.stop();
vid.start();
_videoIsPlaying = true;
// Only continue while the video is still playing
while (!shouldQuit() && !vid.endOfVideo() && vid.isPlaying()) {
// Check for engine quit and video stop key presses
while (_eventMan->pollEvent(_event)) {
switch (_event.type) {
case Common::EVENT_KEYDOWN:
switch (_event.kbd.keycode) {
case Common::KEYCODE_q:
if (_event.kbd.hasFlags(Common::KBD_CTRL))
quitGame();
break;
case Common::KEYCODE_SPACE:
if (skippable) {
vid.stop();
}
break;
default:
break;
}
default:
break;
}
}
if (vid.needsUpdate()) {
const Graphics::Surface *frame = vid.decodeNextFrame();
if (sub && showSubs)
sub->process(vid.getCurFrame());
if (frame) {
if (scaled.getPixels()) {
_renderManager->scaleBuffer(frame->getPixels(), scaled.getPixels(), frame->getWidth(), frame->getHeight(), frame->getFormat().bytesPerPixel, scaled.getWidth(), scaled.getHeight());
frame = &scaled;
}
Common::Rect rect = Common::Rect(x, y, x + finalWidth, y + finalHeight);
_renderManager->copyToScreen(*frame, rect, 0, 0);
_renderManager->processSubs(0);
}
}
// Always update the screen so the mouse continues to render
_system->updateScreen();
_system->delayMillis(vid.getTimeToNextFrame() / 2);
}
_videoIsPlaying = false;
_clock.start();
}
示例4: playVideo
void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect, bool skippable) {
byte bytesPerPixel = videoDecoder.getPixelFormat().bytesPerPixel;
uint16 origWidth = videoDecoder.getWidth();
uint16 origHeight = videoDecoder.getHeight();
uint scale = 1;
// If destRect is empty, no specific scaling was requested. However, we may choose to do scaling anyway
if (destRect.isEmpty()) {
// Most videos are very small. Therefore we do a simple 2x scale
if (origWidth * 2 <= 640 && origHeight * 2 <= 480) {
scale = 2;
}
} else {
// Assume bilinear scaling. AKA calculate the scale from just the width.
// Also assume that the scaling is in integral intervals. AKA no 1.5x scaling
// TODO: Test ^these^ assumptions
scale = destRect.width() / origWidth;
// TODO: Test if we need to support downscale.
}
uint16 pitch = origWidth * bytesPerPixel;
uint16 finalWidth = origWidth * scale;
uint16 finalHeight = origHeight * scale;
byte *scaledVideoFrameBuffer;
if (scale != 1) {
scaledVideoFrameBuffer = new byte[finalWidth * finalHeight * bytesPerPixel];
}
uint16 x = ((WINDOW_WIDTH - finalWidth) / 2) + destRect.left;
uint16 y = ((WINDOW_HEIGHT - finalHeight) / 2) + destRect.top;
_clock.stop();
videoDecoder.start();
// Only continue while the video is still playing
while (!shouldQuit() && !videoDecoder.endOfVideo() && videoDecoder.isPlaying()) {
// Check for engine quit and video stop key presses
while (!videoDecoder.endOfVideo() && videoDecoder.isPlaying() && _eventMan->pollEvent(_event)) {
switch (_event.type) {
case Common::EVENT_KEYDOWN:
switch (_event.kbd.keycode) {
case Common::KEYCODE_q:
if (_event.kbd.hasFlags(Common::KBD_CTRL))
quitGame();
break;
case Common::KEYCODE_SPACE:
if (skippable) {
videoDecoder.stop();
}
break;
default:
break;
}
default:
break;
}
}
if (videoDecoder.needsUpdate()) {
const Graphics::Surface *frame = videoDecoder.decodeNextFrame();
if (frame) {
if (scale != 1) {
scaleBuffer((const byte *)frame->getPixels(), scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale);
_system->copyRectToScreen(scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight);
} else {
_system->copyRectToScreen((const byte *)frame->getPixels(), pitch, x, y, finalWidth, finalHeight);
}
}
}
// Always update the screen so the mouse continues to render
_system->updateScreen();
_system->delayMillis(videoDecoder.getTimeToNextFrame());
}
_clock.start();
if (scale != 1) {
delete[] scaledVideoFrameBuffer;
}
}
示例5: updateMovies
bool VideoManager::updateMovies() {
bool updateScreen = false;
for (VideoList::iterator it = _videos.begin(); it != _videos.end(); ) {
// Check of the video has reached the end
if ((*it)->endOfVideo()) {
if ((*it)->isLooping()) {
// Seek back if looping
(*it)->seek((*it)->getStart());
} else {
// Done; close and continue on
(*it)->close();
it = _videos.erase(it);
continue;
}
}
Video::VideoDecoder *video = (*it)->_video;
// Ignore paused videos
if (video->isPaused()) {
it++;
continue;
}
// Check if we need to draw a frame
if (video->needsUpdate()) {
const Graphics::Surface *frame = video->decodeNextFrame();
Graphics::Surface *convertedFrame = 0;
if (frame && (*it)->isEnabled()) {
Graphics::PixelFormat pixelFormat = _vm->_system->getScreenFormat();
if (frame->format != pixelFormat) {
// We don't support downconverting to 8bpp without having
// support in the codec. Set _enableDither if shows up.
if (pixelFormat.bytesPerPixel == 1) {
warning("Cannot convert high color video frame to 8bpp");
(*it)->close();
it = _videos.erase(it);
continue;
}
// Convert to the current screen format
convertedFrame = frame->convertTo(pixelFormat, video->getPalette());
frame = convertedFrame;
} else if (pixelFormat.bytesPerPixel == 1 && video->hasDirtyPalette()) {
// Set the palette when running in 8bpp mode only
// Don't do this for Myst, which has its own per-stack handling
if (_vm->getGameType() != GType_MYST)
_vm->_system->getPaletteManager()->setPalette(video->getPalette(), 0, 256);
}
// Clip the width/height to make sure we stay on the screen (Myst does this a few times)
uint16 width = MIN<int32>(video->getWidth(), _vm->_system->getWidth() - (*it)->getX());
uint16 height = MIN<int32>(video->getHeight(), _vm->_system->getHeight() - (*it)->getY());
_vm->_system->copyRectToScreen(frame->getPixels(), frame->pitch, (*it)->getX(), (*it)->getY(), width, height);
// We've drawn something to the screen, make sure we update it
updateScreen = true;
// Delete 8bpp conversion surface
if (convertedFrame) {
convertedFrame->free();
delete convertedFrame;
}
}
}
// Check the video time
_vm->doVideoTimer(*it, false);
// Remember to increase the iterator
it++;
}
// Return true if we need to update the screen
return updateScreen;
}