Пример #1
0
unsigned short Writer::getModuleID (const Module *module)
{
	NoiseAssert (module != NULL, module);
	ModuleMap::iterator it = mModules.find(module);
	NoiseAssert (it != mModules.end(), module);
	return it->second;
}
Пример #2
0
bool Image::saveBMP (const char *filename)
{
	NoiseAssert (mData != NULL, mData);
	NoiseAssert (mWidth > 0, mWidth);
	NoiseAssert (mHeight > 0, mHeight);
	FileOutStream stream(filename);
	if (!stream.isOpen())
		return false;
	// BMP Header
	stream.write ("BM", 2);
	unsigned size = 14 + 40 + mWidth * mHeight * 3;
	stream.write (size);
	unsigned res = 0;
	stream.write (res);
	unsigned offset = 54;
	stream.write (offset);

	// BMP properties
	unsigned psize = 40;
	stream.write (psize);
	int w = mWidth;
	stream.write (w);
	int h = mHeight;
	stream.write (h);
	unsigned short planes = 1;
	stream.write (planes);
	unsigned short bpp = 24;
	stream.write (bpp);
	unsigned compression = 0;
	stream.write (compression);
	unsigned sizeImage = mWidth * mHeight * 3;
	stream.write (sizeImage);
	int ppm = 0;
	stream.write (ppm);
	stream.write (ppm);
	unsigned clrUsed = 0;
	stream.write (clrUsed);
	unsigned clrImportant = 0;
	stream.write (clrImportant);
	assert (stream.tell() == offset);

	for (int y=mHeight-1;y>=0;--y)
	{
		unsigned char *buffer = mData+y*mWidth*3;
		for (int x=0;x<mWidth;++x)
		{
			unsigned char r = *buffer++;
			unsigned char g = *buffer++;
			unsigned char b = *buffer++;
			stream.write (b);
			stream.write (g);
			stream.write (r);
		}
	}

	stream.close ();
	return true;
}
Пример #3
0
void Image::create (int width, int height)
{
	NoiseAssert (width > 0, width);
	NoiseAssert (height > 0, height);
	mWidth = width;
	mHeight = height;

	mData = new unsigned char [mWidth*mHeight*3];
}
Пример #4
0
void Writer::writePipeline ()
{
	NoiseAssert (!mModuleVec.empty(), mModuleVec);
	NoiseAssert (mModuleCount == mModules.size(), mModuleCount);
	NoiseAssert (mModuleCount == mModuleVec.size(), mModuleCount);

	unsigned char ver = NOISE_FILE_VERSION;
	mStream.write (ver);
	mStream.write (mModuleCount);
	// writing module properties
	for (ModuleVector::iterator it=mModuleVec.begin();it!=mModuleVec.end();++it)
		writeModule(*it);
	// writing module relations
	for (ModuleVector::iterator it=mModuleVec.begin();it!=mModuleVec.end();++it)
		writeModuleRel(*it);
}
Пример #5
0
void Writer::writeModule (const Module *module)
{
	NoiseAssert (module != NULL, module);
	unsigned short typeID = module->getType();
	mStream.write (typeID);
	module->write (mStream);
}
ThreadedJobQueue::ThreadedJobQueue (size_t numberOfThreads) : mThreadsDone(false), mWorkingThreads(0)
{
	NoiseAssert (numberOfThreads > 0, numberOfThreads);
	for (size_t i=0;i<numberOfThreads;++i)
	{
		mThreads.createThread (threadEntry, this);
	}
}
Пример #7
0
void Writer::writeModuleRel (const Module *module)
{
	NoiseAssert (module != NULL, module);
	for (size_t i=0;i<module->getSourceModuleCount();++i)
	{
		const Module *child = module->getSourceModule(i);
		unsigned short id = getModuleID(child);
		mStream.write (id);
	}
}
Пример #8
0
void GradientRenderer::renderImage (Image &image, const Real *data, JobQueue *jobQueue)
{
	NoiseAssert (mGradients.size() >= 2, mGradients);
	if (!jobQueue)
		jobQueue = System::createOptimalJobQueue();
	unsigned char *buffer = image.getPixelData ();
	int width = image.getWidth();
	for (int y=0;y<image.getHeight();++y)
	{
		jobQueue->addJob (new GradientRendererJob(this, width, data+(y*width), buffer+(y*width*3)));
	}
	jobQueue->executeJobs();
	if (mCallback)
		mCallback->reset ();
	delete jobQueue;
	jobQueue = 0;
}
Пример #9
0
unsigned short Writer::addModule (const Module *module)
{
	NoiseAssert (module != NULL, module);
	ModuleMap::iterator it = mModules.find (module);
	if (it == mModules.end())
	{
		unsigned short id = mModuleCount++;
		mModules.insert(std::make_pair(module, id));
		mModuleVec.push_back (module);

		// add child modules
		for (size_t i=0;i<module->getSourceModuleCount();++i)
		{
			const Module *child = module->getSourceModule(i);
			assert (child);
			addModule (child);
		}

		return id;
	}
	return it->second;
}
void ThreadedJobQueue::addJob (Job *job)
{
	NoiseAssert (job != NULL, job);
	threadpp::Mutex::Lock lk(mMutex);
	mJobs.push (job);
}