bool ClassObjectDelegate::getOwnPropertySlot(QScriptObject* object, JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::PropertySlot &slot) { QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); // for compatibility with the old back-end, normal JS properties // are queried first. if (QScriptObjectDelegate::getOwnPropertySlot(object, exec, propertyName, slot)) return true; QScriptValue scriptObject = engine->scriptValueFromJSCValue(object); QScriptString scriptName; QScriptStringPrivate scriptName_d(engine, propertyName, QScriptStringPrivate::StackAllocated); QScriptStringPrivate::init(scriptName, &scriptName_d); uint id = 0; QScriptClass::QueryFlags flags = m_scriptClass->queryProperty( scriptObject, scriptName, QScriptClass::HandlesReadAccess, &id); if (flags & QScriptClass::HandlesReadAccess) { QScriptValue value = m_scriptClass->property(scriptObject, scriptName, id); slot.setValue(engine->scriptValueToJSCValue(value)); return true; } return false; }
void FrameCapture::saveFrame(QWebFrame *frame) { static int frameCounter = 0; QString fileName(m_fileName); if (frameCounter) { int index = m_fileName.lastIndexOf('.'); fileName = fileName.insert(index, "_frame" + QString::number(frameCounter)); } QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::TextAntialiasing, true); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); frame->documentElement().render(&painter); painter.end(); image.save(fileName); ++frameCounter; foreach(QWebFrame *childFrame, frame->childFrames()) saveFrame(childFrame); }
void draw() { unsigned char mbut = 0; int scrollarea1 = 0; int i; background(gray(122)); uiSetCursor((int)mouseX,(int)mouseY); for (i=0; i<3; i++) uiSetButton(i, 0); if (mousePressed) uiSetButton(mouseButton, 1); createUI(vg, width, height); uiProcess(); drawUI(vg, 0, 0, 0); { int x = mouseX - width/2; int y = mouseY - height/2; if (abs(x) > width/4) { bndJoinAreaOverlay(vg, 0, 0, width, height, 0, (x > 0)); } else if (abs(y) > height/4) { bndJoinAreaOverlay(vg, 0, 0, width, height, 1, (y > 0)); } } if (key == GLFW_KEY_ESCAPE) { quit(); } else if (key == GLFW_KEY_SPACE) { saveFrame("screenshot.png"); } }
bool ClassObjectDelegate::getOwnPropertySlot(QScriptObject* object, JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::PropertySlot &slot) { QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); // for compatibility with the old back-end, normal JS properties // are queried first. if (QScriptObjectDelegate::getOwnPropertySlot(object, exec, propertyName, slot)) return true; QScriptValue scriptObject = engine->scriptValueFromJSCValue(object); QScriptString scriptName; QScriptStringPrivate scriptName_d(engine, propertyName, QScriptStringPrivate::StackAllocated); QScriptStringPrivate::init(scriptName, &scriptName_d); uint id = 0; QScriptClass::QueryFlags flags = m_scriptClass->queryProperty( scriptObject, scriptName, QScriptClass::HandlesReadAccess, &id); if (flags & QScriptClass::HandlesReadAccess) { QScriptValue value = m_scriptClass->property(scriptObject, scriptName, id); if (!value.isValid()) { // The class claims to have the property, but returned an invalid // value. Silently convert to undefined to avoid the invalid value // "escaping" into JS. value = QScriptValue(QScriptValue::UndefinedValue); } slot.setValue(engine->scriptValueToJSCValue(value)); return true; } return false; }
//-------------------------------------------------------------- void gamuzaMain::keyReleased(int key){ bool alt = gamuzaKmap.isAltDown(); // fullscreen toggle if(alt && (key == 'f' || key == 'F')){ gamuzaFullscreen(); } // LIVE CODING if(alt && (key == 'j' || key == 'J')){ liveCodingMode = !liveCodingMode; } // show/hide script code if(alt && (key == 'w' || key == 'W')){ viewCode = !viewCode; } // open file dialog if(alt && (key == 'd' || key == 'D')){ openFileDialog(); } // save frame if(alt && (key == 'o' || key == 'O')){ saveFrame(); } // print frame if(alt && (key == 'p' || key == 'P')){ printFrame(); } }
bool ClassObjectDelegate::getPropertyAttributes(const QScriptObject* object, JSC::ExecState *exec, const JSC::Identifier &propertyName, unsigned &attribs) const { QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); QScriptValue scriptObject = engine->scriptValueFromJSCValue(object); QScriptString scriptName; QScriptStringPrivate scriptName_d(engine, propertyName, QScriptStringPrivate::StackAllocated); QScriptStringPrivate::init(scriptName, &scriptName_d); uint id = 0; QScriptClass::QueryFlags flags = m_scriptClass->queryProperty( scriptObject, scriptName, QScriptClass::HandlesReadAccess, &id); if (flags & QScriptClass::HandlesReadAccess) { QScriptValue::PropertyFlags flags = m_scriptClass->propertyFlags(scriptObject, scriptName, id); attribs = 0; if (flags & QScriptValue::ReadOnly) attribs |= JSC::ReadOnly; if (flags & QScriptValue::SkipInEnumeration) attribs |= JSC::DontEnum; if (flags & QScriptValue::Undeletable) attribs |= JSC::DontDelete; if (flags & QScriptValue::PropertyGetter) attribs |= JSC::Getter; if (flags & QScriptValue::PropertySetter) attribs |= JSC::Setter; attribs |= flags & QScriptValue::UserRange; return true; } return QScriptObjectDelegate::getPropertyAttributes(object, exec, propertyName, attribs); }
// ------------------------------------------------------------------------------ //#pragma mark //#pragma mark Update and Draw void CanonCamera::update() { if(bRecording) { if( (getElapsedSeconds()-mStartTime) >= 1.0f/ mRecordingFPS ){ saveFrame(); mStartTime = getElapsedSeconds(); } } if(isLiveViewing()){ mCanon.downloadData(); } }
void Animation::save(PACKFILE* f) throw (WriteError) { iputl(strlen(name), f); for (int i = 0; name[i]; i++) my_pack_putc(name[i], f); iputl(numFrames, f); iputl(frames[0]->w, f); iputl(frames[0]->h, f); for (int i = 0; i < numFrames; i++) saveFrame(frames[i], delays[i], f); }
bool ClassObjectDelegate::hasInstance(QScriptObject* object, JSC::ExecState *exec, JSC::JSValue value, JSC::JSValue proto) { if (!scriptClass()->supportsExtension(QScriptClass::HasInstance)) return QScriptObjectDelegate::hasInstance(object, exec, value, proto); QScriptValueList args; QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(eng_p, exec); args << eng_p->scriptValueFromJSCValue(object) << eng_p->scriptValueFromJSCValue(value); QVariant result = scriptClass()->extension(QScriptClass::HasInstance, QVariant::fromValue(args)); return result.toBool(); }
void FrameCapture::saveResult(bool ok) { std::cout << std::endl; // crude error-checking if (!ok) { std::cerr << "Failed loading " << qPrintable(m_page.mainFrame()->url().toString()) << std::endl; emit finished(); return; } // save each frame in different image files saveFrame(m_page.mainFrame()); emit finished(); }
void KinectViewer::LiveRenderer::colorStreamingCallback(const Kinect::FrameBuffer& frameBuffer) { /* Forward color frame to the projector: */ projector->setColorFrame(frameBuffer); Vrui::requestUpdate(); if(frameSaver!=0) { /* Time-stamp the incoming frame: */ Kinect::FrameBuffer saveFrame(frameBuffer); saveFrame.timeStamp=timeStamp; /* Forward the time-stamped frame to the frame saver: */ frameSaver->saveColorFrame(saveFrame); } }
bool ClassObjectDelegate::getOwnPropertyDescriptor(QScriptObject *object, JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::PropertyDescriptor &descriptor) { QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); // for compatibility with the old back-end, normal JS properties // are queried first. if (QScriptObjectDelegate::getOwnPropertyDescriptor(object, exec, propertyName, descriptor)) return true; QScriptValue scriptObject = engine->scriptValueFromJSCValue(object); QScriptString scriptName; QScriptStringPrivate scriptName_d(engine, propertyName, QScriptStringPrivate::StackAllocated); QScriptStringPrivate::init(scriptName, &scriptName_d); uint id = 0; QScriptClass::QueryFlags qflags = m_scriptClass->queryProperty( scriptObject, scriptName, QScriptClass::HandlesReadAccess, &id); if (qflags & QScriptClass::HandlesReadAccess) { QScriptValue::PropertyFlags pflags = m_scriptClass->propertyFlags(scriptObject, scriptName, id); unsigned attribs = 0; if (pflags & QScriptValue::ReadOnly) attribs |= JSC::ReadOnly; if (pflags & QScriptValue::SkipInEnumeration) attribs |= JSC::DontEnum; if (pflags & QScriptValue::Undeletable) attribs |= JSC::DontDelete; if (pflags & QScriptValue::PropertyGetter) attribs |= JSC::Getter; if (pflags & QScriptValue::PropertySetter) attribs |= JSC::Setter; attribs |= pflags & QScriptValue::UserRange; // Rather than calling the getter, we could return an access descriptor here. QScriptValue value = m_scriptClass->property(scriptObject, scriptName, id); if (!value.isValid()) { // The class claims to have the property, but returned an invalid // value. Silently convert to undefined to avoid the invalid value // "escaping" into JS. value = QScriptValue(QScriptValue::UndefinedValue); } descriptor.setDescriptor(engine->scriptValueToJSCValue(value), attribs); return true; } return false; }
// wrapper function to handle the normal stuff like // the jsonrpc string and id // for every possible method a seperate function exists void JsonRPC::parseMessage(QWebSocket* client, QString msg) { QJsonDocument jsonRequest = QJsonDocument::fromJson(msg.toUtf8()); QJsonObject reqObj = jsonRequest.object(); RPCRequest request; RPCResponse response; request.jsonrpc = reqObj["jsonrpc"].toString(); request.method = reqObj["method"].toString(); request.params = reqObj["params"].toObject(); request.id = reqObj["id"].toInt(); if(request.method == "getPlaylist") { response = getPlaylist(); } else if(request.method == "loadScene") { response = loadScene(request); } else if(request.method == "getConig") { response = getConfig(); } else if(request.method == "setConfig") { response = setConfig(request); } else if(request.method == "getFrame") { response = getFrame(request); } else if(request.method == "saveFrame") { response = saveFrame(request); } else if(request.method == "newMessure") { response = newMessure(request); } response.id = request.id; response.jsonrpc = "2.0"; QJsonObject resObj; resObj["jsonrpc"] = response.jsonrpc; resObj["result"] = response.result; resObj["id"] = response.id; // create jsondocument from object and send the response to the client QJsonDocument jsonResponse = QJsonDocument(resObj); client->sendTextMessage(QString(jsonResponse.toJson(QJsonDocument::Compact))); }
void ClassObjectDelegate::getOwnPropertyNames(QScriptObject* object, JSC::ExecState *exec, JSC::PropertyNameArray &propertyNames, bool includeNonEnumerable) { QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); QScriptValue scriptObject = engine->scriptValueFromJSCValue(object); QScriptClassPropertyIterator *it = m_scriptClass->newIterator(scriptObject); if (it != 0) { while (it->hasNext()) { it->next(); QString name = it->name().toString(); propertyNames.add(JSC::Identifier(exec, name)); } delete it; } QScriptObjectDelegate::getOwnPropertyNames(object, exec, propertyNames, includeNonEnumerable); }
void ClassObjectDelegate::put(QScriptObject* object, JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::JSValue value, JSC::PutPropertySlot &slot) { QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); QScriptValue scriptObject = engine->scriptValueFromJSCValue(object); QScriptString scriptName; QScriptStringPrivate scriptName_d(engine, propertyName, QScriptStringPrivate::StackAllocated); QScriptStringPrivate::init(scriptName, &scriptName_d); uint id = 0; QScriptClass::QueryFlags flags = m_scriptClass->queryProperty( scriptObject, scriptName, QScriptClass::HandlesWriteAccess, &id); if (flags & QScriptClass::HandlesWriteAccess) { m_scriptClass->setProperty(scriptObject, scriptName, id, engine->scriptValueFromJSCValue(value)); return; } QScriptObjectDelegate::put(object, exec, propertyName, value, slot); }
void KinectViewer::LiveRenderer::depthStreamingCallback(const Kinect::FrameBuffer& frameBuffer) { /* Forward depth frame to the projector: */ projector->setDepthFrame(frameBuffer); #if KINECT_USE_SHADERPROJECTOR Vrui::requestUpdate(); #endif if(frameSaver!=0) { /* Time-stamp the incoming frame: */ Kinect::FrameBuffer saveFrame(frameBuffer); saveFrame.timeStamp=timeStamp; /* Forward the time-stamped frame to the frame saver: */ frameSaver->saveDepthFrame(saveFrame); } }
bool Movie::readFrameAndQueue(void) { // Avoid reading from different threads at the same time sf::Lock l(m_readerMutex); bool flag = true; AVPacket *pkt = NULL; // check we're not at eof if (getEofReached()) flag = false; else { // read frame pkt = (AVPacket *)av_malloc(sizeof(*pkt)); av_init_packet(pkt); int res = av_read_frame(getAVFormatContext(), pkt); // check we didn't reach eof right now if (res < 0) { setEofReached(true); flag = false; av_free_packet(pkt); av_free(pkt); } else { // When a frame has been read, save it if (!saveFrame(pkt)) { if (Movie::usesDebugMessages()) std::cerr << "Movie::ReadFrameAndQueue() - did read unknown packet type" << std::endl; av_free_packet(pkt); av_free(pkt); } } } return flag; }
void DeclarativeObjectDelegate::put(QScriptObject* object, JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::JSValue value, JSC::PutPropertySlot &slot) { QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); QScriptDeclarativeClass::Identifier identifier = (void *)propertyName.ustring().rep(); QScriptDeclarativeClassPrivate *p = QScriptDeclarativeClassPrivate::get(m_class); p->context = reinterpret_cast<QScriptContext *>(exec); QScriptClass::QueryFlags flags = m_class->queryProperty(m_object, identifier, QScriptClass::HandlesWriteAccess); if (flags & QScriptClass::HandlesWriteAccess) { m_class->setProperty(m_object, identifier, engine->scriptValueFromJSCValue(value)); p->context = 0; return; } p->context = 0; QScriptObjectDelegate::put(object, exec, propertyName, value, slot); }
bool ClassObjectDelegate::deleteProperty(QScriptObject* object, JSC::ExecState *exec, const JSC::Identifier &propertyName) { // ### avoid duplication of put() QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); QScriptValue scriptObject = engine->scriptValueFromJSCValue(object); QScriptString scriptName; QScriptStringPrivate scriptName_d(engine, propertyName, QScriptStringPrivate::StackAllocated); QScriptStringPrivate::init(scriptName, &scriptName_d); uint id = 0; QScriptClass::QueryFlags flags = m_scriptClass->queryProperty( scriptObject, scriptName, QScriptClass::HandlesWriteAccess, &id); if (flags & QScriptClass::HandlesWriteAccess) { if (m_scriptClass->propertyFlags(scriptObject, scriptName, id) & QScriptValue::Undeletable) return false; m_scriptClass->setProperty(scriptObject, scriptName, id, QScriptValue()); return true; } return QScriptObjectDelegate::deleteProperty(object, exec, propertyName); }
void ClassObjectDelegate::getOwnPropertyNames(QScriptObject* object, JSC::ExecState *exec, JSC::PropertyNameArray &propertyNames, JSC::EnumerationMode mode) { // For compatibility with the old back-end, normal JS properties // are added first. QScriptObjectDelegate::getOwnPropertyNames(object, exec, propertyNames, mode); QScriptEnginePrivate *engine = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(engine, exec); QScriptValue scriptObject = engine->scriptValueFromJSCValue(object); QScriptClassPropertyIterator *it = m_scriptClass->newIterator(scriptObject); if (it != 0) { while (it->hasNext()) { it->next(); QString name = it->name().toString(); propertyNames.add(JSC::Identifier(exec, name)); } delete it; } }
JSC::JSValue DeclarativeObjectDelegate::call(JSC::ExecState *exec, JSC::JSObject *callee, JSC::JSValue thisValue, const JSC::ArgList &args) { if (!callee->inherits(&QScriptObject::info)) return JSC::throwError(exec, JSC::TypeError, "callee is not a DeclarativeObject object"); QScriptObject *obj = static_cast<QScriptObject*>(callee); QScriptObjectDelegate *delegate = obj->delegate(); if (!delegate || (delegate->type() != QScriptObjectDelegate::DeclarativeClassObject)) return JSC::throwError(exec, JSC::TypeError, "callee is not a DeclarativeObject object"); QScriptDeclarativeClass *scriptClass = static_cast<DeclarativeObjectDelegate*>(delegate)->m_class; QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec); QScript::SaveFrameHelper saveFrame(eng_p, exec); eng_p->pushContext(exec, thisValue, args, callee); QScriptContext *ctxt = eng_p->contextForFrame(eng_p->currentFrame); QScriptValue scriptObject = eng_p->scriptValueFromJSCValue(obj); QScriptDeclarativeClass::Value result = scriptClass->call(static_cast<DeclarativeObjectDelegate*>(delegate)->m_object, ctxt); eng_p->popContext(); return (JSC::JSValue &)(result); }
uint8_t aviWrite::saveAudioFrameDual (uint32_t len, uint8_t * data) { asize2 += len; return saveFrame (len, (uint32_t) 0, data, (uint8_t *) "02wb"); }
int main(int argc, char **argv) { MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); if (argc != 3) { if (rank == 0) printf("Usage: gol <num of generations> <input file>\n"); MPI_Abort(MPI_COMM_WORLD,1); exit(1); } int maxGen = atoi(argv[1]); int numElements = getDeclaredElementCount(argv[2]); int width = sqrt(numElements); int length = numElements / nprocs; uint8_t* myBoard; //length uint8_t* myTop;//width uint8_t* myBot;//width uint8_t* otherBot;// width uint8_t* otherTop;// width otherBot = (uint8_t *) calloc(width, sizeof(int)); otherTop = (uint8_t *) calloc(width, sizeof(int)); //read data here myBoard = getGameTile(argv[2]); int err; int i; MPI_Status status; MPI_Request send_request0, send_request1, recv_request0, recv_request1; for(i = 0; i < maxGen; i++) { //set myTop and myBot myTop = myBoard; //printf("\nrank %d gen %d myTop ", rank, i); //printArray(myTop, width); myBot = myBoard + length - width; //printf("\nrank %d gen %d myBot ", rank, i); //printArray(myBot, width); //send other top and bottoms around, TOP and BOT relative to sender if(nprocs > 1) { if(rank == ROOT) { err = MPI_Isend(myBot, width, MPI_BYTE, rank + 1, BOT, MPI_COMM_WORLD, &send_request0); err = MPI_Irecv(otherTop, width, MPI_BYTE, rank + 1, TOP, MPI_COMM_WORLD, &recv_request0); } else if(rank == nprocs - 1) { err = MPI_Isend(myTop, width, MPI_BYTE, rank - 1, TOP, MPI_COMM_WORLD, &send_request0); err = MPI_Irecv(otherBot, width, MPI_BYTE, rank - 1, BOT, MPI_COMM_WORLD, &recv_request0); } else { err = MPI_Isend(myBot, width, MPI_BYTE, rank + 1, BOT, MPI_COMM_WORLD, &send_request0); err = MPI_Isend(myTop, width, MPI_BYTE, rank - 1, TOP, MPI_COMM_WORLD, &send_request1); err = MPI_Irecv(otherTop, width, MPI_BYTE, rank + 1, TOP, MPI_COMM_WORLD, &recv_request0); err = MPI_Irecv(otherBot, width, MPI_BYTE, rank - 1, BOT, MPI_COMM_WORLD, &recv_request1); err = MPI_Wait(&send_request1, &status); err = MPI_Wait(&recv_request1, &status); } err = MPI_Wait(&send_request0, &status); err = MPI_Wait(&recv_request0, &status); } //insert game/cuda logic here MPI_Barrier(MPI_COMM_WORLD); // printf("\nrank %d gen %d size %d myBoard ", rank, i, length); // printArray(myBoard, length); natural_select(otherBot, otherTop, myBoard, width, width / nprocs); //otherBot and otherTop are Bot and Top pieces coming from other nodes. //Will need to use otherBot to calculate game at the top of the current node, // and use otherTop to calculate game at the bottom of current node. //ask Mike for clarification if this doesn't make sense uint8_t* gameBoard; if(rank == ROOT) { gameBoard = (uint8_t*)calloc(numElements, sizeof(uint8_t)); } MPI_Gather(myBoard, length, MPI_BYTE, gameBoard, length, MPI_BYTE, ROOT, MPI_COMM_WORLD); //output junk if (rank == ROOT) { char* fileout; fileout = (char*)malloc(OUTPUT + DEMOFRAMES * sizeof(char)); printf("output%04d\n", i); sprintf(fileout, "output%04d", i); saveFrame(gameBoard, numElements, fileout); // printf("Generation %d board:\n", i); // printArray(gameBoard, numElements); free(fileout); free(gameBoard); } } //mpi gather junk uint8_t* gameBoard; if(rank == ROOT) { gameBoard = (uint8_t*)calloc(numElements, sizeof(uint8_t)); } MPI_Gather(myBoard, length, MPI_BYTE, gameBoard, length, MPI_BYTE, ROOT, MPI_COMM_WORLD); //output junk if (rank == ROOT) { // printf("made it to outputting!\n"); saveFrame(gameBoard, numElements, "output.txt"); // printf("Final board:\n"); // printArray(gameBoard, numElements); } MPI_Finalize(); return 0; }
void EventRecorder::redisplay(double t, double dt) { if (isRecording) { recordedEvents.push_back(Event(t, dt, TerrainNode::nextGroundHeightAtCamera)); } else if (isPlaying) { ostringstream s; bool replay = true; isPlaying = false; while (replay && lastPlayed < recordedEvents.size()) { Event e = recordedEvents[lastPlayed++]; switch (e.kind) { case Event::DISPLAY: t = e.display.t; dt = e.display.dt; TerrainNode::nextGroundHeightAtCamera = e.display.groundHeight; replay = false; break; case Event::MOUSE: mouseClick((button) e.e.arg1, (state) e.e.arg2, (modifier) e.e.m, e.e.arg3, e.e.arg4); savedX = e.e.arg3; savedY = e.e.arg4; break; case Event::MOTION: mouseMotion(e.e.arg1, e.e.arg2); savedX = e.e.arg1; savedY = e.e.arg2; break; case Event::PASSIVEMOTION: mousePassiveMotion(e.e.arg1, e.e.arg2); savedX = e.e.arg1; savedY = e.e.arg2; break; case Event::WHEEL: mouseWheel((wheel) e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); savedX = e.e.arg2; savedY = e.e.arg3; break; case Event::KEYBOARD: if (e.e.arg4 == 0) { keyTyped(e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); if (e.e.arg1 == 27) { ::exit(0); } } else { keyReleased(e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); } break; case Event::SPECIAL: if (e.e.arg4 == 0) { specialKey((key) e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); } else { specialKeyReleased((key) e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); } break; } } isPlaying = lastPlayed < recordedEvents.size(); } if (next != NULL) { next->redisplay(t, dt); } if (isPlaying) { ptr<FrameBuffer> fb = FrameBuffer::getDefault(); vec4<GLint> vp = fb->getViewport(); fb->setBlend(true, ADD, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ADD, ZERO, ONE); fb->setColorMask(true, true, true, false); fb->setDepthMask(false); fb->setStencilMask(0, 0); correctU->set(vec3f(0.f, 0.f, 1.f)); rescaleU->set(vec4f(2.0f * (float)(savedX + 0.5f * cursW) / vp.z - 1.0f, 2.0f * (float)(vp.w - savedY - 0.5f * cursH) / vp.w - 1.0f, cursW / (float)vp.z, cursH / (float)vp.w)); cursorSamplerU->set(cursor); fb->drawQuad(cursorProg); fb->setBlend(false); fb->setColorMask(true, true, true, true); fb->setDepthMask(true); fb->setStencilMask(0xFFFFFFFF,0xFFFFFFFF); } if (isPlaying && saveVideo) { int frameCount = 0; if (lastSavedEvent >= 0) { double prevTime = recordedEvents[lastSavedEvent].display.t; double curTime = recordedEvents[lastPlayed - 1].display.t; assert(recordedEvents[lastSavedEvent].kind == Event::DISPLAY && prevTime > 0.0); assert(recordedEvents[lastPlayed - 1].kind == Event::DISPLAY && curTime > 0.0); frameCount = int(floor(curTime / 40000.0) - floor(prevTime / 40000.0)); } // if the delay between two recorded frames is more than 1/25 of a second // the first one must be saved several times in the video to keep a video // framerate of 25 frames per second. for (int i = 0; i < frameCount; ++i) { char name[256]; sprintf(name, frames, lastSavedFrame++); saveFrame(name); } lastSavedEvent = lastPlayed - 1; } }
void savePFrame(Frame &frame) { std::stringstream fileName; fileName << ConfigManager::scene_output_directory << FILE_SEPARATOR_CHAR << FRAME_FILE_NAME << "P" << frame.idFrame << SERIAL_EXTENSION_FILENAME; saveFrame(frame, fileName.str().c_str()); }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ static float offset = 0; static float im_save_scale = 1.0; static float line_width = 1.0; if (key == (int)'a') { string timestamp = ofGetTimestampString(); stringstream ss; ss << "frame_" << timestamp << "_" << screen_width << "x" << screen_height << ".png"; saveFrame(ss.str()); } else if (key == (int)'s') { string timestamp = ofGetTimestampString(); stringstream ss; int im_width = screen_width * im_save_scale; int im_height = screen_height * im_save_scale; ss << "fbo_" << timestamp << "_" << im_width << "x" << im_height << ".png"; saveFrameFBO(ss.str(), im_width, im_height); } else if (key == (int)'d') { string timestamp = ofGetTimestampString(); stringstream ss; int im_width = screen_width * im_save_scale; int im_height = screen_height * im_save_scale; ss << "mfbo_" << timestamp << "_" << im_width << "x" << im_height << ".png"; saveFrameMultiFBO(ss.str(), im_width, im_height); } else if (key == (int)'q') { im_save_scale /= 2; cout << "im_save_scale: " << im_save_scale << endl; } else if (key == (int)'w') { im_save_scale *= 2; cout << "im_save_scale: " << im_save_scale << endl; } else if (key == (int)'x') { line_width *= 2; glLineWidth(line_width); } else if (key == (int)'z') { line_width /= 2; glLineWidth(line_width); } else if (key == (int)'=') { x_res *= 2; z_res *= 2; } else if (key == (int)'-') { x_res /= 2; z_res /= 2; } else if (key == (int)'s') { //saveSVG("test.svg"); } else if (key == (int)'=') { offset += 0.5; shader.setUniform2f("u_offset",offset,0); } else if (key == (int)'-') { offset -= 0.5 ; shader.setUniform2f("u_offset",offset,0); } else if (key == (int)'c') { move_camera = !move_camera; } }
//-------------------------------------------------------------- void gamuzaMain::keyReleased(int key){ bool alt = gamuzaKmap.isAltDown(); ////////////////////////////////////////////////////////// // LIVE CODING if(alt && (key == 'j' || key == 'J')){ liveCodingMode = !liveCodingMode; if(liveCodingMode && isFullscreen){ scriptScroll.reset(lcPrevX-20,1,20,lcPrevH-1); }else if(liveCodingMode && !isFullscreen){ scriptScroll.reset(lcPrevX-20,1,20,lcPrevH-1); } } // show/hide script code if(alt && (key == 'w' || key == 'W')){ viewCode = !viewCode; } // LUA lua.scriptKeyReleased(key); ////////////////////////////////////////////////////////// // save frame if(alt && (key == 'o' || key == 'O')){ saveFrame(); } // print frame if(alt && (key == 'p' || key == 'P')){ printFrame(); } // switch between mouse/keyboard Mapping points control if(alt && (key == 'm' || key == 'M')){ activateMouseMapping = !activateMouseMapping; } // TIMELINE if(alt && (key == 't' || key == 'T')){ showTimeline = !showTimeline; if(showTimeline){ timeline.show(); timeline.enableMouse(); }else{ timeline.hide(); timeline.disableMouse(); } } // play/stop the timeline if(alt && (key == 'g' || key == 'G')){ timeline.togglePlay(); } // fullscreen toggle if(alt && (key == 'f' || key == 'F')){ gamuzaFullscreen(); } liveKey = key; }
int main(int argc, char* argv[]) { av_register_all(); AVFormatContext *pFormatCtx; AVCodecContext *pCodecCtx; AVCodec *pCodec; AVFrame *pFrame, *pFrameRGB; struct SwsContext *img_convert_ctx; uint8_t *buffer; fprintf(stdout, "%s\n", argv[1]); pFormatCtx = avformat_alloc_context(); fprintf(stdput, "......................"); if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL) != 0) { fprintf(stderr, "avformat_open_input "); return -1; } if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { fprintf(stderr, "av_find_stream_info "); return -1; } fprintf(stdput, "......................"); av_dump_format(pFormatCtx, 0, argv[1], 0); int videoStream = -1; // int i; // for (i = 0; i < pFormatCtx->nb_streams; ++i) // { // if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) // { // videoStream = i; // break ; // } // } videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &pCodec, 0); if (videoStream == -1) { fprintf(stderr, "videoStream < 0 "); return -1; } fprintf(stdout, "videoStream: %d\n", videoStream); pCodecCtx = pFormatCtx->streams[videoStream]->codec; // pCodec = avcodec_find_decoder(pCodecCtx->codec_id); // if (pCodec == NULL) // { // fprintf(stderr, "Unsupported codec.\n"); // return -1; // } if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) { fprintf(stderr, "Could not open codec.\n"); return -1; } pFrame = avcodec_alloc_frame(); pFrameRGB = avcodec_alloc_frame(); if (pFrameRGB == NULL) { fprintf(stderr, "pFrameRGB == NULL\n"); return -1; } int numBytes; numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); buffer = (uint8_t *)av_malloc(numBytes * (sizeof (uint8_t))); avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); int frameFinished; int index; AVPacket packet; int ret = 0; av_init_packet(&packet); img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL); if (img_convert_ctx == NULL) { fprintf(stderr, "Cannot initialize the conversion context/n"); goto end; } for (index = 0; ; index++) { //memset(&packet, 0, sizeof (packet)); ret = av_read_frame(pFormatCtx, &packet); if (ret < 0) { fprintf(stderr, "read frame ret:%s\n", ret_str(ret)); break ; } //fprintf(stdout, "stream_index:%d\n", packet.stream_index); if (packet.stream_index == videoStream) { ret = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); if (ret < 0) { fprintf(stderr, "decode ret:%s\n", ret_str(ret)); continue ; } fprintf(stdout, "frameFinished %d\n", frameFinished); if (frameFinished) { // img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24, // (AVPicture *)pFrame, pCodecCtx->pix_fmt, // pCodecCtx->width, pCodecCtx->height); sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize); if (index % 100 == 0) { saveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, index); if (index > 10000) { break ; } } } } av_free_packet(&packet);//注中途退出的没有释放 } end: sws_freeContext(img_convert_ctx); av_free(buffer); av_free(pFrameRGB); av_free(pFrame); avcodec_close(pCodecCtx); av_close_input_file(pFormatCtx); fprintf(stderr, "end return.\n"); return 0; }
std::string GUISUMOAbstractView::makeSnapshot(const std::string& destFile) { std::string errorMessage; FXString ext = FXPath::extension(destFile.c_str()); const bool useGL2PS = ext == "ps" || ext == "eps" || ext == "pdf" || ext == "svg" || ext == "tex" || ext == "pgf"; #ifdef HAVE_FFMPEG const bool useVideo = destFile == "" || ext == "h264" || ext == "hevc"; #endif for (int i = 0; i < 10 && !makeCurrent(); ++i) { FXSingleEventThread::sleep(100); } // draw glClearColor( myVisualizationSettings->backgroundColor.red() / 255., myVisualizationSettings->backgroundColor.green() / 255., myVisualizationSettings->backgroundColor.blue() / 255., myVisualizationSettings->backgroundColor.alpha() / 255.); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (myVisualizationSettings->dither) { glEnable(GL_DITHER); } else { glDisable(GL_DITHER); } if (myVisualizationSettings->antialiase) { glEnable(GL_BLEND); glEnable(GL_POLYGON_SMOOTH); glEnable(GL_LINE_SMOOTH); } else { glDisable(GL_BLEND); glDisable(GL_POLYGON_SMOOTH); glDisable(GL_LINE_SMOOTH); } applyGLTransform(); if (useGL2PS) { GLint format = GL2PS_PS; if (ext == "ps") { format = GL2PS_PS; } else if (ext == "eps") { format = GL2PS_EPS; } else if (ext == "pdf") { format = GL2PS_PDF; } else if (ext == "tex") { format = GL2PS_TEX; } else if (ext == "svg") { format = GL2PS_SVG; } else if (ext == "pgf") { format = GL2PS_PGF; } else { return "Could not save '" + destFile + "'.\n Unrecognized format '" + std::string(ext.text()) + "'."; } FILE* fp = fopen(destFile.c_str(), "wb"); if (fp == 0) { return "Could not save '" + destFile + "'.\n Could not open file for writing"; } GLint buffsize = 0, state = GL2PS_OVERFLOW; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); while (state == GL2PS_OVERFLOW) { buffsize += 1024 * 1024; gl2psBeginPage(destFile.c_str(), "sumo-gui; http://sumo.dlr.de", viewport, format, GL2PS_SIMPLE_SORT, GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps"); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); // compute lane width // draw decals (if not in grabbing mode) if (!myUseToolTips) { drawDecals(); if (myVisualizationSettings->showGrid) { paintGLGrid(); } } glLineWidth(1); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); Boundary viewPort = myChanger->getViewport(); float minB[2]; float maxB[2]; minB[0] = viewPort.xmin(); minB[1] = viewPort.ymin(); maxB[0] = viewPort.xmax(); maxB[1] = viewPort.ymax(); myVisualizationSettings->scale = m2p(SUMO_const_laneWidth); glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_LINE); myGrid->Search(minB, maxB, *myVisualizationSettings); if (myVisualizationSettings->showSizeLegend) { displayLegend(); } state = gl2psEndPage(); glFinish(); } fclose(fp); } else { doPaintGL(GL_RENDER, myChanger->getViewport()); if (myVisualizationSettings->showSizeLegend) { displayLegend(); } swapBuffers(); glFinish(); FXColor* buf; FXMALLOC(&buf, FXColor, getWidth()*getHeight()); // read from the back buffer glReadBuffer(GL_BACK); // Read the pixels glReadPixels(0, 0, getWidth(), getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)buf); makeNonCurrent(); update(); // mirror size_t mwidth = getWidth(); size_t mheight = getHeight(); FXColor* paa = buf; FXColor* pbb = buf + mwidth * (mheight - 1); do { FXColor* pa = paa; paa += mwidth; FXColor* pb = pbb; pbb -= mwidth; do { FXColor t = *pa; *pa++ = *pb; *pb++ = t; } while (pa < paa); } while (paa < pbb); try { #ifdef HAVE_FFMPEG if (useVideo) { try { saveFrame(destFile, buf); errorMessage = "video"; } catch (std::runtime_error& err) { errorMessage = err.what(); } } else #endif if (!MFXImageHelper::saveImage(destFile, getWidth(), getHeight(), buf)) { errorMessage = "Could not save '" + destFile + "'."; } } catch (InvalidArgument& e) { errorMessage = "Could not save '" + destFile + "'.\n" + e.what(); } FXFREE(&buf); } return errorMessage; }
int main(int argc, char **argv) { av_register_all(); AVFrame* frame = avcodec_alloc_frame(); if (!frame) { return 1; } AVFormatContext* formatContext = NULL; if (avformat_open_input(&formatContext, argv[1], NULL, NULL) != 0) { av_free(frame); return 1; } if (avformat_find_stream_info(formatContext, NULL) < 0) { av_free(frame); avformat_close_input(&formatContext); return 1; } if (formatContext->nb_streams < 1 || formatContext->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO) { av_free(frame); avformat_close_input(&formatContext); return 1; } AVStream* stream = formatContext->streams[0]; AVCodecContext* codecContext = stream->codec; codecContext->codec = avcodec_find_decoder(codecContext->codec_id); if (codecContext->codec == NULL) { av_free(frame); avcodec_close(codecContext); avformat_close_input(&formatContext); return 1; } else if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0) { av_free(frame); avcodec_close(codecContext); avformat_close_input(&formatContext); return 1; } AVPacket packet; av_init_packet(&packet); int frameNumber = 0; while (av_read_frame(formatContext, &packet) == 0) { if (packet.stream_index == stream->index) { int frameFinished = 0; avcodec_decode_video2(codecContext, frame, &frameFinished, &packet); if (frameFinished) { saveFrame(frame, codecContext->width, codecContext->height, frameNumber++,argv[1]); std::cout << frameNumber << ":\trepeat: " << frame->repeat_pict << "\tkeyframe: " << frame->key_frame << "\tbest_ts: " << frame->best_effort_timestamp << '\n'; } } } int frameFinished = 1; while(frameFinished){ packet.data = NULL; packet.size = 0; int rcode = avcodec_decode_video2(codecContext, frame, &frameFinished, &packet); if(rcode < 0 ){ std::cerr << "[delayed]\tdecide error detected\n"; break; } if (frameFinished) { saveFrame(frame, codecContext->width, codecContext->height, frameNumber++,argv[1]); std::cout << frameNumber << ":\trepeat: " << frame->repeat_pict << "\tkeyframe: " << frame->key_frame << "\tbest_ts: " << frame->best_effort_timestamp << "[delayed]\n"; } } av_free_packet(&packet); av_free(frame); avcodec_close(codecContext); avformat_close_input(&formatContext); return 0; }