Example #1
0
void VideoDevice::saveConfiguration(Misc::ConfigurationFileSection& cfg) const
	{
	/* Get the device's current video format: */
	VideoDataFormat currentFormat=getVideoFormat();
	
	/* Save the current frame size: */
	cfg.storeValueWC("./frameSize",currentFormat.size,Misc::CFixedArrayValueCoder<unsigned int,2>());
	
	/* Save the current frame rate: */
	cfg.storeValue("./frameRate",double(currentFormat.frameIntervalDenominator)/double(currentFormat.frameIntervalCounter));
	
	/* Check if the current pixel format is a valid FourCC code: */
	char fourCCBuffer[5];
	currentFormat.getFourCC(fourCCBuffer);
	bool valid=true;
	for(int i=0;i<4&&valid;++i)
		valid=fourCCBuffer[i]>=32&&fourCCBuffer[i]<127&&fourCCBuffer[i]!='"';
	if(valid)
		{
		/* Save the current pixel format as a FourCC code: */
		cfg.storeValue<std::string>("./pixelFormat",fourCCBuffer);
		}
	else
		{
		/* Save the current pixel format as a hexadecimal number: */
		char hexBuffer[9];
		unsigned int pixelFormat=currentFormat.pixelFormat;
		for(int i=0;i<8;++i,pixelFormat>>=4)
			{
			if((pixelFormat&0x0fU)>=10U)
				hexBuffer[7-i]=(pixelFormat&0x0fU)+'a';
			else
				hexBuffer[7-i]=(pixelFormat&0x0fU)+'0';
			}
		hexBuffer[8]='\0';
		cfg.storeString("./pixelFormatHex",hexBuffer);
		}
	}