Example #1
0
bool ImageLoaderPVM::Save(const Image &cImage, File &cFile)
{
	// Get image buffer, we only support the data type "byte" and "word"
	ImageBuffer *pImageBuffer = cImage.GetBuffer();
	if (pImageBuffer && (pImageBuffer->GetDataFormat() == DataByte || pImageBuffer->GetDataFormat() == DataWord)) {
		// Save the data
		const Vector3i &vSize = pImageBuffer->GetSize();
		writePVMvolume(cFile.GetUrl().GetNativePath().GetASCII(), pImageBuffer->GetData(), vSize.x, vSize.y, vSize.z, (pImageBuffer->GetDataFormat() == DataByte) ? 1 : 2);

		// Done
		return true;
	}

	// Error!
	return false;
}
Example #2
0
bool VolumeLoaderDAT::Save(const Volume &cVolume, File &cFile)
{
	// Get the image holding the volumetric data
	const Image &cImage = cVolume.GetVolumeImage();

	// Get image buffer, we only support the data type "byte" and "word"
	ImageBuffer *pImageBuffer = cImage.GetBuffer();
	if (pImageBuffer && (pImageBuffer->GetDataFormat() == DataByte || pImageBuffer->GetDataFormat() == DataWord)) {
		const Vector3i &vSize = pImageBuffer->GetSize();

		// Construct the object filename
		const String sObjectFilename = cFile.GetUrl().GetTitle() + ".raw";

		// A "dat"-file has simple ASCII content
		cFile.PutS("ObjectFileName: " + sObjectFilename + '\n');	// Example:	"ObjectFileName: Teddybear.raw"
		cFile.PutS("TaggedFileName: ---\n");						// Example:	"TaggedFileName: ---"
		cFile.PutS("Resolution:     " + vSize.ToString() + '\n');	// Example:	"Resolution:     128 128 62"
		cFile.PutS("SliceThickness: 1 1 1\n");						// Example:	"SliceThickness: 2.8 2.8 5"
		if (pImageBuffer->GetDataFormat() == DataByte)				// Example:	"Format:         UCHAR"
			cFile.PutS("Format:         UCHAR\n");
		else
			cFile.PutS("Format:         USHORT\n");
		cFile.PutS("NbrTags:        0\n");							// Example:	"NbrTags:        0"
		cFile.PutS("ObjectType:     TEXTURE_VOLUME_OBJECT\n");		// Example:	"ObjectType:     TEXTURE_VOLUME_OBJECT"
		cFile.PutS("ObjectModel:    RGBA\n");						// Example:	"ObjectModel:    RGBA"
		cFile.PutS("GridType:       EQUIDISTANT\n");				// Example:	"GridType:       EQUIDISTANT"

		{ // Raw data...
			// Get the absolute filename of the raw file
			const String sFilename = cFile.GetUrl().CutFilename() + sObjectFilename;

			// Open the raw file
			File cRawFile(sFilename);
			if (cRawFile.Open(File::FileCreate | File::FileWrite)) {
				// Save the data
				cRawFile.Write(pImageBuffer->GetData(), 1, pImageBuffer->GetDataSize());

				// Done
				return true;
			}
		}
	}

	// Error!
	return false;
}
Example #3
0
bool IEScale::Apply(ImageBuffer &cImageBuffer) const
{
	// Get dimensions
	const uint32 nNewWidth  = m_vNewSize.x;
	const uint32 nNewHeight = m_vNewSize.y;
	const uint32 nOldWidth  = cImageBuffer.GetSize().x;
	const uint32 nOldHeight = cImageBuffer.GetSize().y;

	// [TODO] 3D support
	// [TODO] Currently we only support 'scale down'
	// New width and new height must be >0, ColorPalette as color format is not supported
	if (cImageBuffer.GetColorFormat() != ColorPalette && nNewWidth <= nOldWidth && nNewHeight <= nOldHeight && nNewWidth && nNewHeight) {
		// 3x3 filter matrix
		static const Matrix3x3 mFilter(0.1f, 0.5f, 0.1f,
									   0.5f, 1.0f, 0.5f,
									   0.1f, 0.5f, 0.1f);

		// Create the new image buffer
		ImageBuffer cOldImageBuffer = cImageBuffer;
		// [TODO] Currently compressing data is not implemented, yet
		cImageBuffer.CreateImage(cOldImageBuffer.GetDataFormat(), cOldImageBuffer.GetColorFormat(), Vector3i(nNewWidth, nNewHeight, 1));
//		cImageBuffer.CreateImage(cOldImageBuffer.GetDataFormat(), cOldImageBuffer.GetColorFormat(), Vector3i(nNewWidth, nNewHeight, 1), cOldImageBuffer.GetCompression());

		// Process data format dependent
		switch (cImageBuffer.GetDataFormat()) {
			case DataByte:
			{
				ScaleDownData<uint8> cScaleDownData(cOldImageBuffer, cImageBuffer, nNewWidth, nNewHeight, nOldWidth, nOldHeight, mFilter);
				break;
			}

			case DataWord:
			{
				ScaleDownData<uint16> cScaleDownData(cOldImageBuffer, cImageBuffer, nNewWidth, nNewHeight, nOldWidth, nOldHeight, mFilter);
				break;
			}

			case DataHalf:
			{
				ScaleDownHalfData(cOldImageBuffer, cImageBuffer, nNewWidth, nNewHeight, nOldWidth, nOldHeight, mFilter);
				break;
			}

			case DataFloat:
			{
				ScaleDownData<float> cScaleDownData(cOldImageBuffer, cImageBuffer, nNewWidth, nNewHeight, nOldWidth, nOldHeight, mFilter);
				break;
			}

			case DataDouble:
			{
				ScaleDownData<double> cScaleDownData(cOldImageBuffer, cImageBuffer, nNewWidth, nNewHeight, nOldWidth, nOldHeight, mFilter);
				break;
			}
		}

		// Done
		return true;
	}

	// Error!
	return false;
}