void MovieDecoder::convertAndScaleFrame(PixelFormat format, int& scaledWidth, int& scaledHeight) { calculateDimensions(scaledWidth, scaledHeight); SwsContext* scaleContext = sws_getContext(pVideoCodecContext_->width, pVideoCodecContext_->height, pVideoCodecContext_->pix_fmt, scaledWidth, scaledHeight, format, SWS_BICUBIC, 0, 0, 0); if (0 == scaleContext) { throw std::logic_error("Failed to create resize context"); } AVFrame* convertedFrame = NULL; uint8_t* convertedFrameBuffer = NULL; createAVFrame(&convertedFrame, &convertedFrameBuffer, scaledWidth, scaledHeight, format); sws_scale(scaleContext, pFrame_->data, pFrame_->linesize, 0, pVideoCodecContext_->height, convertedFrame->data, convertedFrame->linesize); sws_freeContext(scaleContext); av_free(pFrame_); av_free(pFrameBuffer_); pFrame_ = convertedFrame; pFrameBuffer_ = convertedFrameBuffer; }
//------------------------------------------- bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){ normalizeFactor = ofGetWidth() / 2.0; // only ever give us triangles. aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT ); aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_NORMALIZE, true); // aiProcess_FlipUVs is for VAR code. Not needed otherwise. Not sure why. unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_Triangulate | aiProcess_FlipUVs; if(optimize) flags |= aiProcess_ImproveCacheLocality | aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes | aiProcess_JoinIdenticalVertices | aiProcess_RemoveRedundantMaterials; if(scene){ clear(); } scene = aiImportFileFromMemory(buffer.getBinaryBuffer(), buffer.size(), flags, extension); if(scene){ calculateDimensions(); loadGLResources(); if(getAnimationCount()) ofLog(OF_LOG_VERBOSE, "scene has animations"); else { ofLog(OF_LOG_VERBOSE, "no animations"); } return true; }else{ ofLog(OF_LOG_ERROR,string("ofxAssimpModelLoader: ") + aiGetErrorString()); return false; } }
void MovieDecoder::convertAndScaleFrame(AVPixelFormat format, int scaledSize, bool maintainAspectRatio, int& scaledWidth, int& scaledHeight) { calculateDimensions(scaledSize, maintainAspectRatio, scaledWidth, scaledHeight); SwsContext* scaleContext = sws_getContext(m_pVideoCodecContext->width, m_pVideoCodecContext->height, m_pVideoCodecContext->pix_fmt, scaledWidth, scaledHeight, format, SWS_BICUBIC, NULL, NULL, NULL); if (NULL == scaleContext) { qDebug() << "Failed to create resize context"; return; } AVFrame* convertedFrame = NULL; uint8_t* convertedFrameBuffer = NULL; createAVFrame(&convertedFrame, &convertedFrameBuffer, scaledWidth, scaledHeight, format); sws_scale(scaleContext, m_pFrame->data, m_pFrame->linesize, 0, m_pVideoCodecContext->height, convertedFrame->data, convertedFrame->linesize); sws_freeContext(scaleContext); av_free(m_pFrame); av_free(m_pFrameBuffer); m_pFrame = convertedFrame; m_pFrameBuffer = convertedFrameBuffer; }
bool ofxAssimpModelLoader::processScene() { normalizeFactor = ofGetWidth() / 2.0; if(scene){ loadGLResources(); update(); calculateDimensions(); if(getAnimationCount()) ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): scene has " << getAnimationCount() << "animations"; else { ofLogVerbose("ofxAssimpModelLoader") << "loadMode(): no animations"; } ofAddListener(ofEvents().exit,this,&ofxAssimpModelLoader::onAppExit); return true; }else{ ofLogError("ofxAssimpModelLoader") << "loadModel(): " + (string) aiGetErrorString(); clear(); return false; } return false; }
void MovieDecoder::convertAndScaleFrame(PixelFormat format, int scaledSize, bool maintainAspectRatio, int& scaledWidth, int& scaledHeight) { calculateDimensions(scaledSize, maintainAspectRatio, scaledWidth, scaledHeight); #ifdef LATEST_GREATEST_FFMPEG // Enable this when it hits the released ffmpeg version SwsContext* scaleContext = sws_alloc_context(); if (scaleContext == nullptr) { throw std::logic_error("Failed to allocate scale context"); } av_set_int(scaleContext, "srcw", m_pVideoCodecContext->width); av_set_int(scaleContext, "srch", m_pVideoCodecContext->height); av_set_int(scaleContext, "src_format", m_pVideoCodecContext->pix_fmt); av_set_int(scaleContext, "dstw", scaledWidth); av_set_int(scaleContext, "dsth", scaledHeight); av_set_int(scaleContext, "dst_format", format); av_set_int(scaleContext, "sws_flags", SWS_BICUBIC); const int* coeff = sws_getCoefficients(SWS_CS_DEFAULT); if (sws_setColorspaceDetails(scaleContext, coeff, m_pVideoCodecContext->pix_fmt, coeff, format, 0, 1<<16, 1<<16) < 0) { sws_freeContext(scaleContext); throw std::logic_error("Failed to set colorspace details"); } if (sws_init_context(scaleContext, nullptr, nullptr) < 0) { sws_freeContext(scaleContext); throw std::logic_error("Failed to initialise scale context"); } #endif SwsContext* scaleContext = sws_getContext(m_pVideoCodecContext->width, m_pVideoCodecContext->height, m_pVideoCodecContext->pix_fmt, scaledWidth, scaledHeight, format, SWS_BICUBIC, nullptr, nullptr, nullptr); if (nullptr == scaleContext) { throw logic_error("Failed to create resize context"); } AVFrame* convertedFrame = nullptr; uint8_t* convertedFrameBuffer = nullptr; createAVFrame(&convertedFrame, &convertedFrameBuffer, scaledWidth, scaledHeight, format); sws_scale(scaleContext, m_pFrame->data, m_pFrame->linesize, 0, m_pVideoCodecContext->height, convertedFrame->data, convertedFrame->linesize); sws_freeContext(scaleContext); av_free(m_pFrame); av_free(m_pFrameBuffer); m_pFrame = convertedFrame; m_pFrameBuffer = convertedFrameBuffer; }
/** * Calculate the geometry of the widget. */ void PreconditionWidget::calculateWidget() { calculateDimensions(); setVisible(true); setX(m_nPosX); setY(m_nY); }
//------------------------------------------ bool ofxAssimpModelLoader::loadModel(string modelName, unsigned extraFlags /* = 0 */){ // if we have a model loaded, unload the f****r. if(scene != NULL){ clear(); } // Load our new path. filepath = modelName; string filepath = ofToDataPath(modelName); //theo added - so we can have models and their textures in sub folders modelFolder = ofFilePath::getEnclosingDirectory(filepath); ofLog(OF_LOG_VERBOSE, "loading model %s", filepath.c_str()); ofLog(OF_LOG_VERBOSE, "loading from folder %s", modelFolder.c_str()); // only ever give us triangles. aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT ); aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_NORMALIZE, true); // aiProcess_FlipUVs is for VAR code. Not needed otherwise. Not sure why. unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_Triangulate | aiProcess_FlipUVs; flags |= extraFlags; /* if(optimize) flags |= aiProcess_ImproveCacheLocality | aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes | aiProcess_JoinIdenticalVertices | aiProcess_RemoveRedundantMaterials; */ scene = aiImportFile(filepath.c_str(), flags); if(scene){ calculateDimensions(); loadGLResources(); if(getAnimationCount()) ofLog(OF_LOG_VERBOSE, "scene has animations"); else { ofLog(OF_LOG_VERBOSE, "no animations"); } collectNodeTransforms(scene, scene->mRootNode); collectBoneTransforms(); return true; }else{ ofLog(OF_LOG_ERROR,string("ofxAssimpModelLoader: ") + aiGetErrorString()); return false; } }
bool PreconditionWidget::activate(IDChangeLog * Log /*= 0*/) { m_scene->resetPastePoint(); UMLWidget::activate(Log); if (m_pOw == NULL) { uDebug() << "cannot make precondition"; return false; } connect(m_pOw, SIGNAL(sigWidgetMoved(Uml::IDType)), this, SLOT(slotWidgetMoved(Uml::IDType))); calculateDimensions(); return true; }
/** * Before calling the original SDL implementation, this method loads in * queued events. * * @param event The ScummVM event */ bool WebOSSdlEventSource::pollEvent(Common::Event &event) { uint32 curTime = g_system->getMillis(); // Event-dependent nitializations for when SDL runs its first poll. if (_firstPoll) { // Set the initial dimensions calculateDimensions(); // Having a mouse pointer on screen when not in Touchpad mode is poor // interface design, because the user won't know whether to tap buttons // or drag the pointer to them. On the first poll, set the appropriate // pointer visibility. g_system->showMouse(_touchpadMode); _firstPoll = false; } // Run down the priority list for queued events. The built-in // event queue runs events on the next poll, which causes many // WebOS devices (and a few game engines) to ignore certain inputs. // Allowing keys and clicks to stay "down" longer is enough to register // the press. if (_queuedEscapeUpTime != 0 && curTime >= _queuedEscapeUpTime) { event.type = Common::EVENT_KEYUP; event.kbd.flags = 0; event.kbd.keycode = Common::KEYCODE_ESCAPE; event.kbd.ascii = Common::ASCII_ESCAPE; _queuedEscapeUpTime = 0; return true; } else if (_queuedSpaceUpTime != 0 && curTime >= _queuedSpaceUpTime) { event.type = Common::EVENT_KEYUP; event.kbd.flags = 0; event.kbd.keycode = Common::KEYCODE_SPACE; event.kbd.ascii = Common::ASCII_SPACE; _queuedSpaceUpTime = 0; return true; } else if (_queuedRUpTime != 0 && curTime >= _queuedRUpTime) { event.type = Common::EVENT_RBUTTONUP; processMouseEvent(event, _curX, _curY); _queuedRUpTime = 0; return true; } else if (_queuedDragTime != 0 && curTime >= _queuedDragTime) { event.type = Common::EVENT_LBUTTONDOWN; _dragging = true; processMouseEvent(event, _curX, _curY); _queuedDragTime = 0; return true; } return SdlEventSource::pollEvent(event); }
/** * Slot when widget is moved. */ void PreconditionWidget::slotWidgetMoved(Uml::ID::Type id) { const Uml::ID::Type idA = m_objectWidget->localID(); if (idA != id) { DEBUG(DBG_SRC) << "id=" << Uml::ID::toString(id) << ": ignoring for idA=" << Uml::ID::toString(idA); return; } m_nY = y(); if (m_nY < minY()) m_nY = minY(); if (m_nY > maxY()) m_nY = maxY(); calculateDimensions(); if (m_scene->selectedCount(true) > 1) return; }
/** * Activates a PreconditionWidget. Connects the WidgetMoved signal from * its m_objectWidget pointer so that PreconditionWidget can adjust to the move of * the object widget. */ bool PreconditionWidget::activate(IDChangeLog * Log /*= 0*/) { m_scene->resetPastePoint(); UMLWidget::activate(Log); loadObjectWidget(); if (!m_objectWidget) { DEBUG(DBG_SRC) << "role A widget " << Uml::ID::toString(m_widgetAId) << " could not be found"; return false; } connect(m_objectWidget, SIGNAL(sigWidgetMoved(Uml::ID::Type)), this, SLOT(slotWidgetMoved(Uml::ID::Type))); calculateDimensions(); return true; }
void PreconditionWidget::slotWidgetMoved(Uml::IDType id) { const Uml::IDType idA = m_pOw->localID(); if (idA != id ) { uDebug() << "id=" << ID2STR(id) << ": ignoring for idA=" << ID2STR(idA); return; } m_nY = getY(); if (m_nY < getMinY()) m_nY = getMinY(); if (m_nY > getMaxY()) m_nY = getMaxY(); calculateDimensions(); if (m_scene->getSelectCount(true) > 1) return; }
//------------------------------------------- bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){ normalizeFactor = ofGetWidth() / 2.0; if(scene != NULL){ clear(); } // only ever give us triangles. aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT ); aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_NORMALIZE, true); // aiProcess_FlipUVs is for VAR code. Not needed otherwise. Not sure why. unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_Triangulate | aiProcess_FlipUVs; if(optimize) flags |= aiProcess_ImproveCacheLocality | aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes | aiProcess_JoinIdenticalVertices | aiProcess_RemoveRedundantMaterials; scene = aiImportFileFromMemory(buffer.getBinaryBuffer(), buffer.size(), flags, extension); if(scene){ calculateDimensions(); loadGLResources(); update(); if(getAnimationCount()) ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): scene has " << getAnimationCount() << "animations"; else { ofLogVerbose("ofxAssimpModelLoader") << "loadMode(): no animations"; } ofAddListener(ofEvents().exit,this,&ofxAssimpModelLoader::onAppExit); return true; }else{ ofLogError("ofxAssimpModelLoader") << "loadModel(): " + (string) aiGetErrorString(); clear(); return false; } }
void MediaPlayer::switchMedia(int amt){ calculateDimensions(); if (groups.size()) { groups[groupIndex]->media[mediaIndex]->stop(); groups[groupIndex]->media[mediaIndex]->setPosition(0.0); mediaIndex +=amt; if (mediaIndex > groups[groupIndex]->media.size()-1){ mediaIndex = 0; shuffleMedia(); } if (mediaIndex < 0){ mediaIndex =groups[groupIndex]->media.size()-1; shuffleMedia(); } if (burstMode == false){ shuffleFrame(); groups[groupIndex]->media[mediaIndex]->play(); groups[groupIndex]->media[mediaIndex]->update(); } } }
void MediaPlayer::update(){ updateBounds(); if (que.size() > 0){ loadFromQue(queIndex); }else{ if (groups.size() > 0){ calculateDimensions(); if (groups[groupIndex]->media.size() >= mediaIndex+1){ manageLooping(); timedelta = ofGetLastFrameTime(); if (loopingIndex == 1){ if (groups[groupIndex]->media[mediaIndex]->getPosition() > .96){ cout << "media done"; switchMedia(1); } } groups[groupIndex]->media[mediaIndex]->update(); } } } }
void MediaPlayer::keyPressed(int key){ cout << "key: "<<key<<"\n"; if (key == 115){ // s // stretch index toggles between stretch modes that affect the aspect ratio of the image // 0: "stretch" traditional stretching, the images is stretch to fill the entire screen // 1: "preserve" the image is fit to the screen to preserve its aspect ratio, but leave the entire screen filled // 2: "fit" the image is fitted to the screen to present the image in its entirety, leaving black gaps and not filling the entire canvas stretchIndex+= 1; if (stretchIndex > 2){ stretchIndex = 0; } calculateDimensions(); } if (key == 98){ // b // triggers burst mode // enter description for what burst mode does burstToggle(); } if (key == 117){ // u // toggles UI drawing or not if (drawUI == true){ drawUI = false; }else{ drawUI = true; } } if (key == 2304){ // shift // you can create different containers of gifs called "groups" this could be a collection of happy gifs, sad gifs, animae gifs.. whatever // you can then use the up and down keys to toggle between these groups for a better performance if (addingToGroup == false){ addingToGroup = true; }else{ addingToGroup = false; } } if (queing == false){ if (key == 357){ //up // TOGGLES A NEW GROUP resetMedia(); if (groupIndex+1 >= groups.size()){ groupIndex = 0; }else{ groupIndex+=1; } groups[groupIndex]->media[mediaIndex]->play(); } if (key == 359){ // down // TOGGLES A NEW GROUP resetMedia(); if (groupIndex-1 < 0){ groupIndex = groups.size()-1; }else{ groupIndex-=1; } groups[groupIndex]->media[mediaIndex]->play(); } if (key == 108){ // l loopingIndex+=1; // 1: it will stop on last frme // 2: start back on first frame // 3: get to last frame, then ping pong back and forth } if (key == 358){ // right // if you are not in burst mode, this will just switch you to the next gif, if you are in burst mode // then this will go to the next frame of the gif instead of skipping to the next gif. if (burstMode == false){ switchMedia(1); }else{ burstMedia(1); if (groups[groupIndex]->media[mediaIndex]->getPosition() >= .99){ switchMedia(1); groups[groupIndex]->media[mediaIndex]->update(); groups[groupIndex]->media[mediaIndex]->setPosition(0); } } } if (key == 356){ // left if (burstMode == false){ switchMedia(-1); }else{ burstMedia(-1); // this is when you get the beginning of the gif if (groups[groupIndex]->media[mediaIndex]->getPosition() == 0){ switchMedia(-1); groups[groupIndex]->media[mediaIndex]->update(); groups[groupIndex]->media[mediaIndex]->setPosition(.95); } } } } }
/** * Activates a MessageWidget. Connects its m_pOw[] pointers * to UMLObjects and also send signals about its FloatingTextWidget. */ bool MessageWidget::activate(IDChangeLog * /*Log = 0*/) { m_scene->resetPastePoint(); // UMLWidget::activate(Log); CHECK: I don't think we need this ? if (m_pOw[Uml::RoleType::A] == NULL) { UMLWidget *pWA = m_scene->findWidget(m_widgetAId); if (pWA == NULL) { DEBUG(DBG_SRC) << "role A object " << Uml::ID::toString(m_widgetAId) << " not found"; return false; } m_pOw[Uml::RoleType::A] = dynamic_cast<ObjectWidget*>(pWA); if (m_pOw[Uml::RoleType::A] == NULL) { DEBUG(DBG_SRC) << "role A widget " << Uml::ID::toString(m_widgetAId) << " is not an ObjectWidget"; return false; } } if (m_pOw[Uml::RoleType::B] == NULL) { UMLWidget *pWB = m_scene->findWidget(m_widgetBId); if (pWB == NULL) { DEBUG(DBG_SRC) << "role B object " << Uml::ID::toString(m_widgetBId) << " not found"; return false; } m_pOw[Uml::RoleType::B] = dynamic_cast<ObjectWidget*>(pWB); if (m_pOw[Uml::RoleType::B] == NULL) { DEBUG(DBG_SRC) << "role B widget " << Uml::ID::toString(m_widgetBId) << " is not an ObjectWidget"; return false; } } updateResizability(); UMLClassifier *c = dynamic_cast<UMLClassifier*>(m_pOw[Uml::RoleType::B]->umlObject()); UMLOperation *op = NULL; if (c && !m_CustomOp.isEmpty()) { Uml::ID::Type opId = Uml::ID::fromString(m_CustomOp); op = dynamic_cast<UMLOperation*>(c->findChildObjectById(opId, true)); if (op) { // If the UMLOperation is set, m_CustomOp isn't used anyway. // Just setting it empty for the sake of sanity. m_CustomOp.clear(); } } if(!m_pFText) { Uml::TextRole::Enum tr = Uml::TextRole::Seq_Message; if (isSelf()) tr = Uml::TextRole::Seq_Message_Self; m_pFText = new FloatingTextWidget(m_scene, tr, operationText(m_scene)); m_scene->addFloatingTextWidget(m_pFText); m_pFText->setFontCmd(UMLWidget::font()); } if (op) setOperation(op); // This requires a valid m_pFText. setLinkAndTextPos(); m_pFText->setText(QString()); m_pFText->setActivated(); QString messageText = m_pFText->text(); m_pFText->setVisible(messageText.length() > 1); connect(m_pOw[Uml::RoleType::A], SIGNAL(sigWidgetMoved(Uml::ID::Type)), this, SLOT(slotWidgetMoved(Uml::ID::Type))); connect(m_pOw[Uml::RoleType::B], SIGNAL(sigWidgetMoved(Uml::ID::Type)), this, SLOT(slotWidgetMoved(Uml::ID::Type))); connect(this, SIGNAL(sigMessageMoved()), m_pOw[Uml::RoleType::A], SLOT(slotMessageMoved())); connect(this, SIGNAL(sigMessageMoved()), m_pOw[Uml::RoleType::B], SLOT(slotMessageMoved())); m_pOw[Uml::RoleType::A]->messageAdded(this); if (!isSelf()) m_pOw[Uml::RoleType::B]->messageAdded(this); // Calculate the size and position of the message widget calculateDimensions(); // Position the floating text accordingly setTextPosition(); emit sigMessageMoved(); return true; }
/** * Calculate the geometry of the widget. */ void MessageWidget::calculateWidget() { setMessageText(m_pFText); calculateDimensions(); setVisible(true); }