예제 #1
0
파일: QuasiStack.cpp 프로젝트: dakyri/qua
/*
 * TODO XXX FIXME WTF this seems incredibly dangerous legacy code ... it's unused fortunately but should be fully deprecated
 */
bool
QuasiStack::GetFrameMap(frame_map_hdr *&map)
{
	short i;
	frame_map_hdr	*p;
	long	map_len;
	map_len = sizeof(frame_map_hdr) * (countFrames()+1);
	map_len += stackable->countControllers()*(sizeof(StabEnt *));
	map_len += countFrames()*(sizeof(QuasiStack *));

	char	*cmap = (char *)malloc(map_len);
	map = (frame_map_hdr *)cmap;
	p = map;
	p->context = context;
	p->frame_handle = this;
	p->n_children = countFrames();
	p->n_controller = stackable->countControllers();
	p->status = locusStatus;
	cmap += sizeof(frame_map_hdr);
	StabEnt	**q = (StabEnt **)cmap;
	for (i=0; i<stackable->countControllers(); i++) {
		*q = stackable->controller(i);
		q++;
	}
	cmap += sizeof(StabEnt *) * stackable->countControllers();
	QuasiStack **r = (QuasiStack **)cmap;
	for (i=0; i<countFrames(); i++) {
		if (frameAt(i)) {
//			fprintf(stderr, "\tname %s\n", stackable->Controller(i)->uniqueName());
		}
		*r++ = frameAt(i);
	}

	return true;
}
예제 #2
0
파일: QuasiStack.cpp 프로젝트: dakyri/qua
status_t
QuasiStack::LoadSnapshotChildren(tinyxml2::XMLElement *element, std::vector<std::string> textFragments)
{
	tinyxml2::XMLNode*childNode = element->FirstChildElement();
	int childStackCount = 0;
	while (childNode != nullptr) {
		tinyxml2::XMLText *textNode;
		tinyxml2::XMLElement *elementNode;
		if ((textNode = childNode->ToText()) != nullptr) {
			textFragments.push_back(textNode->Value());
		}
		else if ((elementNode = childNode->ToElement()) != nullptr) {
			const char *namestr = elementNode->Value();
			if (namestr == "stack") {
				QuasiStack	*child = nullptr;
				if (childStackCount < countFrames()) {
					child = frameAt(childStackCount);
				}
				if (child) {
					child->LoadSnapshotElement(elementNode);
				}
				childStackCount++;
			} else {
				LoadSnapshotElement(elementNode);
			}
		}

		childNode = childNode->NextSibling();
	}

	return B_OK;
}
void FrameSequence::loadFrames(string path, int maxFrameCount) {
  ofImage image;

  int firstFrameIndex = getFirstFrameIndex(path);
  if (firstFrameIndex < 0) {
    cout << "Couldn't find frame: " << path << "/frame%04d.png" << endl;
    return;
  }

  image.loadImage(path + "/frame" + ofToString(firstFrameIndex, 0, 4, '0') + ".png");

  int totalFrameCount = countFrames(path, firstFrameIndex);
  totalFrameCount = MIN(maxFrameCount, totalFrameCount);

  allocatePixels(totalFrameCount, image.width, image.height);

  cout << "Loading " << frameCount << " frames " << endl
    << "\tPath: " << path << endl
    << "\tDimensions: " << frameWidth << "x" << frameHeight << endl
    << "\tSize: " << floor(frameCount * frameWidth * frameHeight * 3 / 1024 / 1024) << " MB" << endl;

  for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
    image.loadImage(path + "/frame" + ofToString(firstFrameIndex + frameIndex, 0, 4, '0') + ".png");
    image.setImageType(OF_IMAGE_COLOR);

    for (int i = 0; i < frameWidth * frameHeight * 3; i++) {
      unsigned char c = image.getPixels()[i];
      pixels[frameIndex * frameWidth * frameHeight * 3 + i] = c;
    }
  }

  cout << "Loading complete." << endl;
}
예제 #4
0
bool PaintWidget::reset()
{
    emit zoomEvent(scaleVal = 1);

    setFrame(0.0, false);
    if( !painter.isEnabled() ) return false;

    setViewportColor( QColor( 100, 100, 100 ) );

    BACKGROUND( painter.background )->reset();

    setViewportType( fixedViewport );
    setViewportFixedSize( QSize( 640, 480 ) );

    for(int i=0; i<painter.layers.size(); i++)
    {
        while( painter.layers[i]->countObjects() > 0 )
                delete painter.layers[i]->remove( 0 );
        delete painter.layers[i];
    }
    painter.layers.clear();

    painter.addLayer(true, false, tr("Layer ") + "0");
    painter.selection.reset();
    painter.inKeyPressedHandler = false;
    painter.inSelectionMode = false;
    update();

    emit figureSelected( 0, -1);
    emit allLayersChanged();
    emit countFramesChanged( countFrames() );

    return true;
}
예제 #5
0
bool PaintWidget::load( QDataStream &stream )
{
	if( !painter.isEnabled() ) return false;


	for(int i=0; i<painter.layers.size(); i++)
	{
		while( painter.layers[i]->countObjects() > 0 )
				delete painter.layers[i]->remove( 0 );
		delete painter.layers[i];
	}

	painter.layers.clear();
	QString signature;
	stream >> signature;

	if( signature != SIGNATURE )
		return false;

	stream >> transparent;
	stream >> viewportColor;

	if( !transparent )
		setViewportColor( viewportColor );
	else
		doViewportTransparent();

	BACKGROUND( painter.background )->load( stream );

	int type;
	stream >> type;
	setViewportType( ( ViewportType ) type );

	stream >> painter.size;
	setViewportFixedSize( painter.size );
	int countLayer;
	stream >> countLayer;

	for(int i=0; i<countLayer; i++)
	{
			QString name;
			stream >> name;
			painter.addLayer(true, false, name);
			painter.layers[i]->loadLayer( stream );
	}

	painter.selection.reset();
	painter.inKeyPressedHandler = false;
	painter.inSelectionMode = false;
	update();

	emit figureSelected( 0 , -1);
	emit allLayersChanged();
	emit countFramesChanged( countFrames() );

    setFrame(0.0, false);

	return true;
}
예제 #6
0
파일: draw.c 프로젝트: te-bachi/cgr
void draw_screen( ) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);             // Clear the screen and the depth buffer
    
    draw3D();
    countFrames();
    
    SDL_GL_SwapBuffers( );                                          // Swap the buffers
}
예제 #7
0
bool LogPlayer::open(const char* fileName)
{
  InBinaryFile file(fileName);
  if(file.exists())
  {
    clear();
    file >> *this;
    stop();
    countFrames();
    return true;
  }
예제 #8
0
파일: k3bmaddecoder.cpp 프로젝트: KDE/k3b
bool K3bMadDecoder::analyseFileInternal( K3b::Msf& frames, int& samplerate, int& ch )
{
    initDecoderInternal();
    frames = countFrames();
    if( frames > 0 ) {
        // we convert mono to stereo all by ourselves. :)
        ch = 2;
        samplerate = d->firstHeader.samplerate;
        return true;
    }
    else
        return false;
}
예제 #9
0
void PaintWidget::deleteFrame(int position)
{
	if(position == 0)
	{
		return;
	}

	painter.selection.reset();
	painter.layers[painter.currentLayer]->deleteFrameForLayer(position);
	painter.setFrame( position, false );
	painter.update();
	emit countFramesChanged( countFrames() );
	emit frameChanged( frame() );
	emit StateChanged("Delete frame");
}
예제 #10
0
파일: QuasiStack.cpp 프로젝트: dakyri/qua
bool
QuasiStack::Thunk()
{
	QDBMSG_STK("Thunk(%s%x, ", isLeaf?"leaf ":"",this)
	QDBMSG_STK("%d higher frames, exec %x)\n", higherFrame.CountItems(),stackable);

	if (countFrames() == 0 && !isLeaf && context->type == TypedValue::S_LAMBDA) {
		Lambda	*executable = (Lambda *)stackable;
		if (executable && executable->mainBlock) {
			if (!executable->mainBlock->StackOMatic(this, 0)) {
				return true;
			}		
		}
	} else {
		return false;
	}
	return false;
}
예제 #11
0
void PaintWidget::deleteSelected()
{
	if( !canDeleteSelected() )
		return;

	int count = painter.selection.countSelected();

	for( int i = 0; i < count; i++ )
	{
		delete painter.layers[painter.currentLayer]->remove(
				painter.layers[painter.currentLayer]->objectIndex(
						GOBJECT(painter.selection.selected( i ))) );
	}

	painter.selection.reset();
	update();

	emit figureSelected( painter.currentLayer , -1);
	emit allLayersChanged();
	emit countFramesChanged( countFrames() );
	emit StateChanged("Delete");
}
예제 #12
0
파일: QuasiStack.cpp 프로젝트: dakyri/qua
status_t
QuasiStack::SaveSnapshot(ostream &out, const char *label)
{
	status_t	err=B_NO_ERROR;

	bool saveChildStacks = true;
	if (stackable) {
		bool saveBinaryValues = true;
		bool saveSymbolicValues = true;
		if (stackable->stackSize > 0 && saveBinaryValues) {
			out << "<stack name=\"" << label << "\" length=\"" << stackable->stackSize << "\" encoding=\"base64\">" << endl;
			std::string outb = Base64::Encode((uchar *)vars, stackable->stackSize);
			out << outb << endl;
		}
		else {
			out << "<stack name=\"" << label << "\">" << endl;
		}

		if (stackable->sym) {
			StabEnt	*p = stackable->sym->children;
			while (p!= nullptr) {
				switch (p->type) {
					case TypedValue::S_BOOL:
					case TypedValue::S_SHORT:
					case TypedValue::S_BYTE:
					case TypedValue::S_INT:
					case TypedValue::S_TIME:
					case TypedValue::S_FLOAT:
					case TypedValue::S_LONG:
					case TypedValue::S_DOUBLE: {
						if (p->refType == TypedValue::REF_STACK) {
							err=p->SaveSimpleTypeSnapshot(out, stacker, this);
						}
						break;
					}

					case TypedValue::S_CHANNEL: {
						if (p->refType == TypedValue::REF_STACK) {
							err=p->SaveSimpleTypeSnapshot(out, stacker, this);
						}
						break;
					}
					case TypedValue::S_TAKE: {
						break;
					}
					case TypedValue::S_CLIP: {
						if (p->refType == TypedValue::REF_STACK) {
							err=p->SaveSimpleTypeSnapshot(out, stacker, this);
						}
						break;
					}
				}
				p = p->sibling;
			}
		}
	} else {
		out << "<stack name=\""<<label<<"\">"<<endl;
	}
	if (saveChildStacks) {
		for (short i=0; i<countFrames(); i++) {
			QuasiStack	*s = frameAt(i);
			std::string chlabel = "child";
			if (s->callingBlock) {
				switch (s->callingBlock->type) {
					case Block::C_CALL:
						if (s->callingBlock->crap.call.crap.lambda) {
							chlabel = s->callingBlock->crap.call.crap.lambda->sym->name;
						} else {
							chlabel = "call";
						}
						break;
					case Block::C_VST:
						if (s->callingBlock->crap.call.crap.vstplugin) {
							chlabel = s->callingBlock->crap.call.crap.vstplugin->sym->name;
						} else {
							chlabel = "vst";
						}
						break;

					case Block::C_GENERIC_PLAYER:
					case Block::C_MIDI_PLAYER:
					case Block::C_SAMPLE_PLAYER:
					case Block::C_TUNEDSAMPLE_PLAYER:
					case Block::C_STREAM_PLAYER:
					case Block::C_MARKOV_PLAYER:
						chlabel = findClipPlayer(s->callingBlock->type);
						break;
				}
			}
			s->SaveSnapshot(out, chlabel.c_str());
		}
	}
	out <<"</stack>"<<endl;
	return err;
}
예제 #13
0
	istream& GenericKAnimFile::load(istream& in, int verbosity) {
		if(verbosity >= 1) {
			cout << "Loading anim file information..." << endl;
		}

		uint32_t magic;
		io.raw_read_integer(in, magic);
		if(!in || magic != MAGIC_NUMBER) {
			throw(KToolsError("Attempt to read a non-anim file as anim."));
		}

		io.raw_read_integer(in, version);

		if(version & 0xffff) {
			io.setNativeSource();
		}
		else {
			io.setInverseNativeSource();
			io.reorder(version);
		}

		if(verbosity >= 2) {
			cout << "Got anim version " << version << "." << endl;
		}

		versionRequire();


		uint32_t numelements;
		uint32_t numframes;
		uint32_t numevents;
		uint32_t numanims;

		io.read_integer(in, numelements);
		io.read_integer(in, numframes);
		io.read_integer(in, numevents);
		io.read_integer(in, numanims);

		setAnimCount(numanims);

		if(verbosity >= 1) {
			cout << "Loading " << numanims << " animations..." << endl;
		}

		if(!loadPre_all_anims(in, verbosity)) {
			throw(KToolsError("Failed to load animations."));
		}

		if(countElements() != numelements) {
			throw(KToolsError("Corrupt anim file (invalid element count)."));
		}
		if(countFrames() != numframes) {
			throw(KToolsError("Corrupt anim file (invalid frame count)."));
		}
		if(countEvents() != numevents) {
			throw(KToolsError("Corrupt anim file (invalid event count)."));
		}


		if(!shouldHaveHashTable() || !in || in.peek() == EOF) {
			if(shouldHaveHashTable()) {
				std::cerr << "WARNING: Missing hash table at the end of the anim file. Generating automatic names." << std::endl;
			}

			FallbackKAnimNamer namer;

			(void)loadPost_all_anims(in, namer, verbosity);
		}
		else {
			if(verbosity >= 1) {
				cout << "Loading anim hash table..." << endl;
			}

			hashtable_t ht;
			uint32_t htsize;
			io.read_integer(in, htsize);
			for(uint32_t i = 0; i < htsize; i++) {
				hash_t h;
				io.read_integer(in, h);

				string& str = ht[h];
				io.read_len_string<uint32_t>(in, str);

				if(verbosity >= 5) {
					cout << "\tGot 0x" << hex << h << dec << " => \"" << str << "\"" << endl;
				}
			}

			HashTableKAnimNamer namer(ht);

			(void)loadPost_all_anims(in, namer, verbosity);
		}


		if(in.peek() != EOF) {
			std::cerr << "Warning: There is leftover data in the input anim file." << std::endl;
		}

		return in;
	}
예제 #14
0
void qAnimationDlg::render()
{
	if (!m_view3d)
	{
		assert(false);
		return;
	}
	QString outputFilename = outputFileLineEdit->text();

	//save to persistent settings
	{
		QSettings settings;
		settings.beginGroup("qAnimation");
		settings.setValue("filename", outputFilename);
		settings.endGroup();
	}

	setEnabled(false);

	//count the total number of frames
	int frameCount = countFrames(0);
	int fps = fpsSpinBox->value();
	int superRes = superResolutionSpinBox->value();

	//show progress dialog
	QProgressDialog progressDialog(QString("Frames: %1").arg(frameCount), "Cancel", 0, frameCount, this);
	progressDialog.setWindowTitle("Render");
	progressDialog.show();
	QApplication::processEvents();

#ifdef QFFMPEG_SUPPORT
	//get original viewport size
	QSize originalViewSize = m_view3d->size();

	//hack: as the encoder requires that the video dimensions are multiples of 8, we resize the window a little bit...
	{
		//find the nearest multiples of 8
		QSize customSize = originalViewSize;
		if (originalViewSize.width() % 8 || originalViewSize.height() % 8)
		{
			if (originalViewSize.width() % 8)
				customSize.setWidth((originalViewSize.width() / 8 + 1) * 8);
			if (originalViewSize.height() % 8)
				customSize.setHeight((originalViewSize.height() / 8 + 1) * 8);
			m_view3d->resize(customSize);
			QApplication::processEvents();
		}
	}

	int bitrate = bitrateSpinBox->value() * 1024;
	int gop = fps;
	QVideoEncoder encoder(outputFilename, m_view3d->width(), m_view3d->height(), bitrate, gop, static_cast<unsigned>(fpsSpinBox->value()));
	QString errorString;
	if (!encoder.open(&errorString))
	{
		QMessageBox::critical(this, "Error", QString("Failed to open file for output: %1").arg(errorString));
		setEnabled(true);
		return;
	}
#endif

	bool lodWasEnabled = m_view3d->isLODEnabled();
	m_view3d->setLODEnabled(false);

	int frameIndex = 0;
	bool success = true;
	size_t vp1 = 0, vp2 = 0;
	while (getNextSegment(vp1, vp2))
	{
		Step& step1 = m_videoSteps[vp1];
		Step& step2 = m_videoSteps[vp2];

		ViewInterpolate interpolator(step1.viewport, step2.viewport);
		int frameCount = static_cast<int>( fps * step1.duration_sec );
		interpolator.setMaxStep(frameCount);

		cc2DViewportObject current_params;
		while ( interpolator.nextView( current_params ) )
		{
			applyViewport ( &current_params );

			//render to image
			QImage image = m_view3d->renderToImage(superRes, false, false, true );

			if (image.isNull())
			{
				QMessageBox::critical(this, "Error", "Failed to grab the screen!");
				success = false;
				break;
			}

			if (superRes > 1)
			{
				image = image.scaled(image.width()/superRes, image.height()/superRes, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
			}

#ifdef QFFMPEG_SUPPORT
			if (!encoder.encodeImage(image, frameIndex, &errorString))
			{
				QMessageBox::critical(this, "Error", QString("Failed to encode frame #%1: %2").arg(frameIndex+1).arg(errorString));
				success = false;
				break;
			}
#else
			QString filename = QString("frame_%1.png").arg(frameIndex, 6, 10, QChar('0'));
			QString fullPath = QDir(outputFilename).filePath(filename);
			if (!image.save(fullPath))
			{
				QMessageBox::critical(this, "Error", QString("Failed to save frame #%1").arg(frameIndex+1));
				success = false;
				break;
			}
#endif
			++frameIndex;
			progressDialog.setValue(frameIndex);
			QApplication::processEvents();
			if (progressDialog.wasCanceled())
			{
				QMessageBox::warning(this, "Warning", QString("Process has been cancelled"));
				success = false;
				break;
			}
		}

		if (!success)
		{
			break;
		}

		if (vp2 == 0)
		{
			//stop loop here!
			break;
		}
		vp1 = vp2;
	}

	m_view3d->setLODEnabled(lodWasEnabled);

#ifdef QFFMPEG_SUPPORT
	encoder.close();

	//hack: restore original size
	m_view3d->resize(originalViewSize);
	QApplication::processEvents();
#endif
	
	progressDialog.hide();
	QApplication::processEvents();

	if (success)
	{
		QMessageBox::information(this, "Job done", "The animation has been saved successfully");
	}

	setEnabled(true);
}
예제 #15
0
void qAnimationDlg::preview()
{
	//we'll take the rendering time into account!
	QElapsedTimer timer;
	timer.start();

	setEnabled(false);

	size_t vp1 = previewFromSelectedCheckBox->isChecked() ? static_cast<size_t>(getCurrentStepIndex()) : 0;

	//count the total number of frames
	int frameCount = countFrames(loopCheckBox->isChecked() ? 0 : vp1);
	int fps = fpsSpinBox->value();

	//show progress dialog
	QProgressDialog progressDialog(QString("Frames: %1").arg(frameCount), "Cancel", 0, frameCount, this);
	progressDialog.setWindowTitle("Preview");
	progressDialog.show();
	progressDialog.setModal(true);
	progressDialog.setAutoClose(false);
	QApplication::processEvents();

	assert(stepSelectionList->count() >= m_videoSteps.size());

	int frameIndex = 0;
	size_t vp2 = 0;
	while (getNextSegment(vp1, vp2))
	{
		Step& step1 = m_videoSteps[vp1];
		Step& step2 = m_videoSteps[vp2];

		//theoretical waiting time per frame
		qint64 delay_ms = static_cast<int>(1000 * step1.duration_sec / fps);
		int frameCount = static_cast<int>( fps * step1.duration_sec );

		ViewInterpolate interpolator(step1.viewport, step2.viewport);
		interpolator.setMaxStep(frameCount);
		cc2DViewportObject currentParams;
		while ( interpolator.nextView( currentParams ) )
		{
			timer.restart();
			applyViewport ( &currentParams );
			qint64 dt_ms = timer.elapsed();

			progressDialog.setValue(++frameIndex);
			QApplication::processEvents();
			if (progressDialog.wasCanceled())
			{
				break;
			}

			//remaining time
			if (dt_ms < delay_ms)
			{
				int wait_ms = static_cast<int>(delay_ms - dt_ms);
#if defined(CC_WINDOWS)
				::Sleep( wait_ms );
#else
				usleep( wait_ms * 1000 );
#endif
			}
		}
		if (progressDialog.wasCanceled())
		{
			break;
		}

		if (vp2 == 0)
		{
			assert(loopCheckBox->isChecked());
			frameIndex = 0;
		}
		vp1 = vp2;
	}

	//reset view
	onCurrentStepChanged(getCurrentStepIndex());

	setEnabled(true);
}