コード例 #1
0
ファイル: ImageFile.cpp プロジェクト: AtomicFiction/cortex
MStatus ImageFile::load( MImage& image, unsigned int idx )
{
	MStatus s;

	assert( idx == 0 );
	assert( m_rData	);
	assert( m_gData	);
	assert( m_bData	);

	s = image.create( m_width, m_height, m_numChannels, MImage::kFloat );
	assert(s);

	image.setRGBA( true );

	populateImage( image.floatPixels() );

	return MS::kSuccess;
}
コード例 #2
0
MStatus metro_image::load( MImage& image, unsigned int idx)
{
	image.create( m_width, m_height, 4, MImage::kByte);

	squish::u8 *src = m_image;
	unsigned char *pixels = image.pixels();
	for( unsigned y = m_height; y != 0 ; y-- ) {
		for( unsigned x = 0; x < m_width; x++ ) {
			unsigned i = (y - 1) * m_height + x;
			*pixels++ = src[i * 4];
			*pixels++ = src[i * 4 + 1];
			*pixels++ = src[i * 4 + 2];
			*pixels++ = src[i * 4 + 3];
		}
	}
	image.setRGBA( true );

	return MS::kSuccess;
}
コード例 #3
0
MStatus ToMayaImageConverter::convert( MImage &image ) const
{
	MStatus s;
	ConstImagePrimitivePtr toConvert = runTimeCast<const ImagePrimitive>( srcParameter()->getValidatedValue() );
	assert( toConvert );

	unsigned int width = toConvert->getDisplayWindow().size().x + 1;
	unsigned int height = toConvert->getDisplayWindow().size().y + 1;

	MImage::MPixelType pixelType = MImage::kUnknown;
	switch( typeParameter()->getNumericValue() )
	{
		case Float :
			pixelType = MImage::kFloat;
			break;
		case Byte:
			pixelType = MImage::kByte;
			break;
		default :

			assert( false );
	}

	/// Get the channels RGBA at the front, in that order, if they exist
	vector<string> desiredChannelOrder;
	desiredChannelOrder.push_back( "R" );
	desiredChannelOrder.push_back( "G" );
	desiredChannelOrder.push_back( "B" );
	desiredChannelOrder.push_back( "A" );

	vector<string> channelNames;
	for  ( PrimitiveVariableMap::const_iterator it = toConvert->variables.begin(); it != toConvert->variables.end(); ++it )
	{
		channelNames.push_back( it->first );
	}

	vector<string> filteredNames;

	int rgbChannelsFound = 0;
	bool haveAlpha = false;
	for ( vector<string>::const_iterator it = desiredChannelOrder.begin(); it != desiredChannelOrder.end(); ++it )
	{
		vector<string>::iterator res = find( channelNames.begin(), channelNames.end(), *it );
		if ( res != channelNames.end() )
		{
			if ( *it == "A" )
			{
				haveAlpha = true;
			}
			else
			{
				rgbChannelsFound ++;
			}
			channelNames.erase( res );
			filteredNames.push_back( *it );
		}
	}
	channelNames = filteredNames;

	if ( rgbChannelsFound != 3 )
	{
		return MS::kFailure;
	}

	unsigned numChannels = 4; // We always add an alpha if one is not present.

	/// \todo We could optimise here by not recreating the image if the existing one matches our exact requirements
	s = image.create( width, height, numChannels, pixelType );
	if ( !s )
	{
		return s;
	}

	image.setRGBA( true );

	unsigned channelOffset = 0;
	for ( vector<string>::const_iterator it = channelNames.begin(); it != channelNames.end(); ++it, ++channelOffset )
	{
		DataPtr dataContainer = toConvert->variables.find( *it )->second.data;
		assert( dataContainer );

		switch( pixelType )
		{
			case MImage::kFloat :
			{
				ChannelConverter<float> converter( *it );
				FloatVectorDataPtr channelData = despatchTypedData<
					ChannelConverter<float>,
					TypeTraits::IsNumericVectorTypedData,
					ChannelConverter<float>::ErrorHandler
				>( dataContainer, converter );

				writeChannel<float>( image, channelData, channelOffset, numChannels );
			}

				break;
			case MImage::kByte:
			{
				ChannelConverter<unsigned char> converter( *it );
				UCharVectorDataPtr channelData = despatchTypedData<
					ChannelConverter<unsigned char>,
					TypeTraits::IsNumericVectorTypedData,
					ChannelConverter<unsigned char>::ErrorHandler
				>( dataContainer, converter );

				writeChannel<unsigned char>( image, channelData, channelOffset, numChannels );
			}

				break;
			default :

				assert( false );
		}
	}

	if ( !haveAlpha )
	{
		switch( pixelType )
		{
			case MImage::kFloat :
			{
				writeAlpha<float>( image, 1.0 );
			}
			break;
			case MImage::kByte :
			{
				writeAlpha<unsigned char>( image, 255 );
			}
			break;
			default :

				assert( false );
		}
	}

	PrimitiveVariableMap::const_iterator it = toConvert->variables.find( "Z" );
	if ( it != toConvert->variables.end() )
	{
			DataPtr dataContainer = it->second.data;
			assert( dataContainer );

			ChannelConverter<float> converter( "Z" );
			FloatVectorDataPtr channelData = despatchTypedData<
				ChannelConverter<float>,
				TypeTraits::IsNumericVectorTypedData,
				ChannelConverter<float>::ErrorHandler
			>( dataContainer, converter );

			writeDepth( image, channelData );
	}

	return MS::kSuccess;
}