예제 #1
0
	float Animator::_calculateValue(float k)
	{
		if (this->delay > 0.0f)
		{
			return (this->discreteStep != 0 ? (float)((int)(this->offset / this->discreteStep) * this->discreteStep) : this->offset);
		}
		float time = this->timer;
		if (this->isExpired())
		{
			if (this->reset)
			{
				return (this->discreteStep != 0 ? (float)((int)(this->offset / this->discreteStep) * this->discreteStep) : this->offset);
			}
			time = this->periods / habs(this->speed);
		}
		float result = 0.0f;
		switch (this->animationFunction)
		{
		case Object::Linear:
			result = time * this->speed * this->amplitude;
			break;
		case Object::Sine:
			result = (float)dsin(time * this->speed * 360) * this->amplitude;
			break;
		case Object::Square:
			result = (hmodf(time * this->speed, 1.0f) < 0.5f ? this->amplitude : -this->amplitude);
			break;
		case Object::Saw:
			result = (hmodf(time * this->speed + 0.5f, 1.0f) - 0.5f) * 2 * this->amplitude;
			break;
		case Object::Triangle:
			result = hmodf(time * this->speed, 1.0f);
			if (!is_in_range(result, 0.25f, 0.75f))
			{
				result = (hmodf(time * this->speed + 0.5f, 1.0f) - 0.5f) * 4 * this->amplitude;
			}
			else
			{
				result = -(hmodf(time * this->speed - 0.25f, 1.0f) - 0.25f) * 4 * this->amplitude;
			}
			break;
		case Object::Random:
			result = hrandf(-this->speed * this->amplitude, this->speed * this->amplitude);
			break;
		case Object::Hover:
			if ((this->amplitude >= 0.0f) == this->parent->isCursorInside())
			{
				result = hmin(this->value - this->offset + k * this->speed, (float)habs(this->amplitude));
			}
			else
			{
				result = hmax(this->value - this->offset - k * this->speed, -(float)habs(this->amplitude));
			}
			break;
		case Object::Custom:
			result = (this->customFunction != NULL ? this->customFunction(this, time) : this->value);
			break;
		}
		return (this->discreteStep != 0 ? (float)((int)((result + this->offset) / this->discreteStep) * this->discreteStep) : (result + this->offset));
	}
예제 #2
0
파일: Font.cpp 프로젝트: boisei0/arcreator
	float Font::getTextWidth(chstr text)
	{
		// using static definitions to avoid memory allocation for optimization
		static float textX = 0.0f;
		static float textW = 0.0f;
		static float ax = 0.0f;
		static float aw = 0.0f;
		static float scale = 1.0f;
		static CharacterDefinition* character = NULL;
		static std::basic_string<unsigned int> chars;
		textX = 0.0f;
		textW = 0.0f;
		ax = 0.0f;
		aw = 0.0f;
		scale = this->getScale();
		chars = text.u_str();
		for_itert (unsigned int, i, 0, chars.size())
		{
			character = &this->characters[chars[i]];
			if (textX < -character->bx * scale)
			{
				ax = (character->aw - character->bx) * scale;
				aw = character->w * scale;
			}
			else
			{
				ax = character->aw * scale;
				aw = (character->w + character->bx) * scale;
			}
			textW = textX + hmax(ax, aw);
			textX += ax;
		}
		return textW;
	}
예제 #3
0
int main(const int argc, const char **argv)
{

  MYLOGVERB = LOG_INFO;
  ModelManager *mgr = new ModelManager("Extract Patches for Hmax with Feature Learning");

  mgr->exportOptions(MC_RECURSE);

  // required arguments
  // <c1patchesDir> <trainPosDir>

  if (mgr->parseCommandLine(
                            (const int)argc, (const char**)argv, "<c1patchesDir> <trainPosDir>", 2, 2) == false)
    return 1;

  // Create a temp HmaxFL object to extract C1Patches
  std::vector<int> c1ScaleSS(2);
  c1ScaleSS[0] = 1; c1ScaleSS[1] = 3;
  std::vector<int> c1SpaceSS(2);
  c1SpaceSS[0] = 10; c1SpaceSS[1] = 11;
  // desired frame sizes [11 and 13]
  HmaxFL hmax(NORI,c1SpaceSS,c1ScaleSS,2,true,1.0F,1.0F,0.3F,4.05F,-0.05F,11,2);

  std::string c1PatchesBaseDir;
  std::string trainPosName; // Directory where positive images are

  c1PatchesBaseDir = mgr->getExtraArg(0);
  trainPosName = mgr->getExtraArg(1);

  // Extract random patches from a set of images in a positive training directory
  std::vector<std::string> trainPos = hmax.readDir(trainPosName);
  int posTrainSize = trainPos.size();

  //Image<byte> inputb;

  Image<float> trainPosImage;

  std::cout << "Scanned training and testing images" << std::endl;

  std::vector<int> pS(4);
  pS[0] = 4; pS[1] = 8, pS[2] = 12; pS[3] = 16;

  std::srand(time(0));
  for(int i=0;i<NUM_PATCHES_PER_SIZE;i++){
    // Randomly select an image from the list
    unsigned int imInd = static_cast<unsigned int>(floor((rand()-1.0F)/RAND_MAX*posTrainSize));
    trainPosImage = Raster::ReadFloat(trainPos[imInd]);
    // Learn the appropriate simple S2 patches from the C1 results
    hmax.extractRandC1Patch(c1PatchesBaseDir,trainPosImage,i,pS);
  }

  std::cout << "Completed extraction of C1 Patches" << std::endl;

  return 0;
}
예제 #4
0
파일: slist.c 프로젝트: KDE/calligra
void slist_fixheight(struct slist_node *n) {
	int c;
	c = hmax(
			n->children[NODE_LEFT] ? n->children[NODE_LEFT]->height : 0,
			n->children[NODE_RIGHT] ? n->children[NODE_RIGHT]->height : 0
			) + 1;
	if (c != n->height) {
		n->height = c;
		if (n->parent != NULL) {
			slist_fixheight(n->parent);
		}
	}
}
예제 #5
0
	void ScrollBar::addScrollValueEnd(float multiplier)
	{
		this->addScrollValue(hmax(habs(this->gridSize), (float)(int)(habs(ScrollBar::ScrollDistance) * multiplier)));
	}
예제 #6
0
	void Playlist::queueSounds(harray<hstr> names)
	{
		this->players += names.mapped(&_map_createPlayer);
		this->index = hmax(this->index, 0);
	}
예제 #7
0
	void Playlist::queueSound(chstr name)
	{
		this->players += xal::manager->createPlayer(name);
		this->index = hmax(this->index, 0);
	}
예제 #8
0
	int FileBase::_fwrite(const void* buffer, int count)
	{
		int result = (int)_platformWriteFile(buffer, 1, count, (FILE*)this->cfile);
		this->dataSize = hmax(this->dataSize, this->_fposition());
		return result;
	}
예제 #9
0
파일: slist.c 프로젝트: KDE/calligra
void slist_unlink(struct slist *l, struct slist_node *n) {
	struct slist_node *pn;
	struct slist_node *bn;
	struct slist_node *ln;
	struct slist_node *rn;
	struct slist_node *su;
	struct slist_node *cn;
	struct slist_node **sn;

	assert(l != NULL);
	assert(n != NULL);
	
	bn = NULL;
	pn = n->parent;
	ln = n->children[NODE_LEFT];
	rn = n->children[NODE_RIGHT];

	// fix the linked list
	if (n->brothers[NODE_NEXT] != NULL) {
		n->brothers[NODE_NEXT]->brothers[NODE_PREV] = n->brothers[NODE_PREV];
	}
	else {
		l->ends[NODE_LAST] = n->brothers[NODE_PREV];
	}
	if (n->brothers[NODE_PREV] != NULL) {
		n->brothers[NODE_PREV]->brothers[NODE_NEXT] = n->brothers[NODE_NEXT];
	}
	else {
		l->ends[NODE_FIRST] = n->brothers[NODE_NEXT];
	}
	
	if (!ln) {
		if (pn && (pn->children[NODE_LEFT] == n)) {
			pn->children[NODE_LEFT] = rn;
		}
		else if (pn) {
			pn->children[NODE_RIGHT] = rn;
		}
		else {
			l->root = rn;
		}
		if (rn) {
			rn->parent = pn;
		}
		bn = pn;
	}
	else if (!rn) {
		if (pn && (pn->children[NODE_LEFT] == n)) {
			pn->children[NODE_LEFT] = ln;
		}
		else if (pn) {
			pn->children[NODE_RIGHT] = ln;
		}
		else {
			l->root = ln;
		}
		if (ln) {
			ln->parent = pn;
		}
		bn = pn;
	}
	else {
		su = ln;
		while (su->children[NODE_RIGHT]) {
			su = su->children[NODE_RIGHT];
		}
		// su is the largest node that is smaller than n
		if (su == ln) {
			// in this case we can simply shift the node up
			su->children[NODE_RIGHT] = rn;
			su->count += rn ? rn->count : 0;
			su->height = hmax(su->height, rn ? rn->height+1 : 1);
			// rebalancing needed at this node
			bn = pn;
			rn->parent = su;
		}
		else {
			if (su->children[NODE_LEFT]) {
				su->parent->children[NODE_RIGHT] = su->children[NODE_LEFT];
				su->children[NODE_LEFT]->parent = su->parent;
			}
			else {
				su->parent->children[NODE_RIGHT] = NULL;
			}
			cn = su->parent;
			while (cn != n) {
				cn->count = (cn->children[NODE_LEFT] ? 
					cn->children[NODE_LEFT]->count : 0) + 
					(cn->children[NODE_RIGHT] ? 
					cn->children[NODE_RIGHT]->count : 0) + 1;
				cn->height = hmax (
					(cn->children[NODE_LEFT] ? 
					cn->children[NODE_LEFT]->height : 0),
					(cn->children[NODE_RIGHT] ? 
					cn->children[NODE_RIGHT]->height : 0))+1;
				cn = cn->parent;
			}
			assert(ln);
			assert(rn);
			su->children[NODE_LEFT] = ln;
			ln->parent = su;
			su->children[NODE_RIGHT] = rn;
			rn->parent = su;
			su->count = (rn ? rn->count : 0) + (ln ? ln->count : 0) + 1;
			su->height = hmax(ln ? ln->height : 0, rn ? rn->height : 0) + 1;
			// rebalancing needed
			bn = pn;
		}
		// fix the pn pointer to the node
		su->parent = pn;
		if (pn) {
			sn = pn->children[NODE_RIGHT] == n ? 
				&pn->children[NODE_RIGHT] : 
				&pn->children[NODE_LEFT];
			*sn = su;
		}
		else {
			l->root = su;
		}
	}
	slist_dec_count(pn);
	if (bn) {
		slist_rebalance(l, bn);
	}
	n->parent = NULL;
	n->children[NODE_LEFT] = NULL;
	n->children[NODE_RIGHT] = NULL;
	n->brothers[NODE_LEFT] = NULL;
	n->brothers[NODE_RIGHT] = NULL;
}
예제 #10
0
	void VideoObject::_createClip(bool waitForCache)
	{
		hstr path = getFullPath();
		april::Image::Format textureFormat = _getTextureFormat();
		destroyResources();
		
		if (path.endsWith(".mp4"))
		{
			hstr archive = hresource::getArchive();
			if (archive != "")
			{
				path = hrdir::joinPath(archive, path);
			}
		}
		
		try
		{
			TheoraOutputMode mode = TH_RGBA;

			if (textureFormat == april::Image::FORMAT_RGBA)				mode = TH_RGBA;
			else if (textureFormat == april::Image::FORMAT_RGBX)		mode = TH_RGBX;
			else if (textureFormat == april::Image::FORMAT_BGRA)		mode = TH_BGRA;
			else if (textureFormat == april::Image::FORMAT_BGRX)		mode = TH_BGRX;
			else if (textureFormat == april::Image::FORMAT_ARGB)		mode = TH_ARGB;
			else if (textureFormat == april::Image::FORMAT_XRGB)		mode = TH_XRGB;
			else if (textureFormat == april::Image::FORMAT_ABGR)		mode = TH_ABGR;
			else if (textureFormat == april::Image::FORMAT_XBGR)		mode = TH_XBGR;
			else if (textureFormat == april::Image::FORMAT_RGB)			mode = TH_RGBX;
			else if (textureFormat == april::Image::FORMAT_BGR)			mode = TH_BGRX;
			else if (textureFormat == april::Image::FORMAT_GRAYSCALE)	mode = TH_GREY;
			int ram = april::getSystemInfo().ram;
			int precached = 16;
#if defined(_ANDROID) || defined(_WINRT) && !defined(_WINP8)
			// Android and WinRT libtheoraplayer uses an optimized libtheora which is faster, but still slower than
			// a native hardware accelerated codec. So (for now) we use a larger precache to counter it. Though, WinP8 can't handle this memory-wise.
			if (ram > 512) precached = 32;
#else
			if      (ram < 384) precached = 6;
			else if (ram < 512) precached = 8;
			else if (ram < 1024)
			{
				if (path.contains("lowres")) precached = 16;
				else precached = 8;
			}
#endif
			
			if (path.endsWith("mp4"))
			{
				try
				{
					if (april::window->getName() == "OpenKODE") // because mp4's are opened via apple's api, and that doesn't play nice with OpenKODE dir structure.
						mClip = gVideoManager->createVideoClip(hrdir::joinPath("res", path).cStr(), mode, precached);
					else
						mClip = gVideoManager->createVideoClip(path.cStr(), mode, precached);
				}
				catch (_TheoraGenericException& e)
				{
					// pass the exception further as a hexception so the general system can understand it
					throw Exception(e.getErrorText().c_str());
				}
			}
			else
			{
				if (!path.endsWith(".mp4") && ram > 256)
				{
					hresource r;
					r.open(path);
					unsigned long size = (unsigned long) r.size();
					TheoraDataSource* source;

					// additional performance optimization: preload file in RAM to speed up decoding, every bit counts on Android/WinRT ARM
					// but only for "reasonably" sized files
					if (size < 64 * 1024 * 1024)
					{
						hlog::write(logTag, "Preloading video file to memory: " + path);
						unsigned char* data = new unsigned char[size];
						r.readRaw(data, (int) size);
						source = new TheoraMemoryFileDataSource(data, size, path.cStr());
					}
					else
					{
						source = new AprilVideoDataSource(path);
					}
					
					mClip = gVideoManager->createVideoClip(source, mode, precached);
					r.close();
					hlog::write(logTag, "Created video clip.");
				}
				else
				{
					mClip = gVideoManager->createVideoClip(new AprilVideoDataSource(path), mode, precached);
				}
			}
		}
		catch (_TheoraGenericException& e)
		{
			throw Exception(e.getErrorText().c_str());
		}
		if (mClip->getWidth() == 0) throw Exception("Failed to load video file: " + path);
		mClip->setAutoRestart(mLoop);
		
		int tw = mClip->getWidth();
		int th = mClip->getHeight();
		april::RenderSystem::Caps caps = april::rendersys->getCaps();
		if (!caps.npotTexturesLimited && !caps.npotTextures)
		{
			tw = hpotceil(tw);
			th = hpotceil(th);
		}

		hlog::write(logTag, "Creating video textures for " + mClipName);
		april::Texture* tex;
		for (int i = 0; i < 2; i++)
		{
			tex = april::rendersys->createTexture(tw, th, april::Color::Clear, textureFormat, april::Texture::TYPE_VOLATILE);
			tex->setAddressMode(april::Texture::ADDRESS_CLAMP);
			mTexture = new aprilui::Texture(tex->getFilename() + "_" + hstr(i + 1), tex);

			mVideoImage = new aprilui::Image(mTexture, "video_img_" + hstr(i + 1), grect(mClip->getSubFrameOffsetX(), mClip->getSubFrameOffsetY(), mClip->getSubFrameWidth(), mClip->getSubFrameHeight()));
			mVideoImage->setBlendMode(mBlendMode);

			mTextures += mTexture;
			mVideoImages += mVideoImage;
		}

		if (waitForCache && mInitialPrecacheFactor > 0.0f)
		{
			float factor = hmax(2.0f / mClip->getNumPrecachedFrames(), mInitialPrecacheFactor);
			float precached = (float) mClip->getNumReadyFrames() / mClip->getNumPrecachedFrames();
			if (precached < factor)
			{
				hlog::writef(logTag, "Waiting for cache (%.1f%% / %.1f%%): %s", precached * 100.0f, factor * 100.0f, path.cStr());
				if (factor > 0)
				{
					precached = mClip->waitForCache(factor, mInitialPrecacheTimeout); // better to wait a while then to display an empty image
				}
				if (precached < factor)
				{
					hlog::writef(logTag, "Initial precache cached %.1f%% frames, target precache factor was %.1f%%", precached * 100.0f, factor * 100.0f);
				}
			}
		}

		if (mAudioName != "")
		{
			hstr category = "video";
			if (mAudioName.contains("/"))
			{
				harray<hstr> folders = hrdir::splitPath(mAudioName);
				hstr path_category = folders[folders.size() - 2];
				if (xal::manager->hasCategory(path_category)) category = path_category;
			}
			if (category == "video" && !xal::manager->hasCategory("video"))
			{
#if defined(_WINRT) || defined(_ANDROID)
				xal::manager->createCategory("video", xal::ON_DEMAND, xal::DISK);
#else
				if (april::getSystemInfo().ram >= 512)
				{
					xal::manager->createCategory("video", xal::STREAMED, xal::RAM);
				}
				else
				{
					xal::manager->createCategory("video", xal::STREAMED, xal::DISK);
				}
#endif
			}
			mSound = xal::manager->createSound(hrdir::joinPath(hrdir::joinPath(this->dataset->getFilePath(), "video"), mAudioName), category);
			if (mSound != NULL)
			{
				mAudioPlayer = xal::manager->createPlayer(mSound->getName());
				mTimer = new AudioVideoTimer(this, mAudioPlayer, mAudioSyncOffset);
			}
		}
		if (mTimer == NULL)
		{
			mTimer = new VideoTimer(this);
		}
		mClip->setTimer(mTimer);
		mClip->setPlaybackSpeed(mSpeed);
		update(0); // to grab the first frame.
	}
예제 #11
0
	void VideoObject::setInitialPrecacheTimeout(float value)
	{
		mInitialPrecacheTimeout = hmax(value, 0.0f);
	}