示例#1
0
void SurfaceT<T>::init( ImageSourceRef imageSource, const SurfaceConstraints &constraints, boost::tribool alpha )
{
	int32_t width = imageSource->getWidth();
	int32_t height = imageSource->getHeight();
	bool hasAlpha;
	if( alpha )
		hasAlpha = true;
	else if( ! alpha )
		hasAlpha = false;
	else
		hasAlpha = imageSource->hasAlpha();

	SurfaceChannelOrder channelOrder = constraints.getChannelOrder( hasAlpha );
	int32_t rowBytes = constraints.getRowBytes( width, channelOrder, sizeof(T) );
	
	T *data = new T[height * rowBytes];

	mObj = std::shared_ptr<Obj>( new Obj( width, height, channelOrder, data, true, rowBytes ) );
	mObj->mIsPremultiplied = imageSource->isPremultiplied();
	
	std::shared_ptr<ImageTargetSurface<T> > target = ImageTargetSurface<T>::createRef( this );
	imageSource->load( target );
	
	// if the image doesn't have alpha but we do, set ourselves to be full alpha
	if( hasAlpha && ( ! imageSource->hasAlpha() ) ) {
		ip::fill( &getChannelAlpha(), CHANTRAIT<T>::max() );
	}	
}
示例#2
0
GWorldPtr createGWorld( ImageSourceRef imageSource )
{
	ImageTargetGWorldRef target = ImageTargetGWorld::createRef( imageSource );
	imageSource->load( target );
	target->finalize();
	return target->getGWorld();
}
示例#3
0
CVPixelBufferRef createCvPixelBuffer( ImageSourceRef imageSource, bool convertToYpCbCr )
{
	ImageTargetCvPixelBufferRef target = ImageTargetCvPixelBuffer::createRef( imageSource, convertToYpCbCr );
	imageSource->load( target );
	target->finalize();
	::CVPixelBufferRef result( target->getCvPixelBuffer() );
	::CVPixelBufferRetain( result );
	return result;
}
示例#4
0
ChannelT<T>::ChannelT( const ImageSourceRef &imageSource )
{
	mWidth = imageSource->getWidth();
	mHeight = imageSource->getHeight();
	mRowBytes = mWidth * sizeof(T);
	mIncrement = 1;

	mDataStore = shared_ptr<T>( new T[mHeight * (mRowBytes/sizeof(T))], std::default_delete<T[]>() );
	mData = mDataStore.get();
	
	shared_ptr<ImageTargetChannel<T>> target = ImageTargetChannel<T>::createRef( this );
	imageSource->load( target );
}
示例#5
0
ChannelT<T>::ChannelT( ImageSourceRef imageSource )
{
	int32_t width = imageSource->getWidth();
	int32_t height = imageSource->getHeight();
	int32_t rowBytes = width * sizeof(T);

	T *data = new T[height * (rowBytes/sizeof(T))];

	mObj = shared_ptr<Obj>( new Obj( width, height, rowBytes, 1, true, data ) );
	mObj->mOwnsData = true;
	
	shared_ptr<ImageTargetChannel<T> > target = ImageTargetChannel<T>::createRef( this );
	imageSource->load( target );	
}
示例#6
0
void writeImage( ImageTargetRef imageTarget, const ImageSourceRef &imageSource )
{
	imageSource->load( imageTarget );
	imageTarget->finalize();
}
示例#7
0
void Texture::init( ImageSourceRef imageSource, const Format &format )
{
	mObj->mDoNotDispose = false;
	mObj->mTarget = format.mTarget;
	mObj->mWidth = mObj->mCleanWidth = imageSource->getWidth();
	mObj->mHeight = mObj->mCleanHeight = imageSource->getHeight();

#if defined( CINDER_MAC )
	bool supportsTextureFloat = gl::isExtensionAvailable( "GL_ARB_texture_float" );
#elif defined( CINDER_MSW )
	bool supportsTextureFloat = GLEE_ARB_texture_float != 0;
#endif
	
	// Set the internal format based on the image's color space
	if( format.isAutoInternalFormat() ) {
		switch( imageSource->getColorModel() ) {
#if ! defined( CINDER_GLES )
			case ImageIo::CM_RGB:
				if( imageSource->getDataType() == ImageIo::UINT8 )
					mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_RGBA8 : GL_RGB8;
				else if( imageSource->getDataType() == ImageIo::UINT16 )
					mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_RGBA16 : GL_RGB16;
				else if( imageSource->getDataType() == ImageIo::FLOAT32 && supportsTextureFloat )
					mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_RGBA32F_ARB : GL_RGB32F_ARB;
				else
					mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_RGBA : GL_RGB;
			break;
			case ImageIo::CM_GRAY:
				if( imageSource->getDataType() == ImageIo::UINT8 )
					mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_LUMINANCE8_ALPHA8 : GL_LUMINANCE8;
				else if( imageSource->getDataType() == ImageIo::UINT16 )
					mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_LUMINANCE16_ALPHA16 : GL_LUMINANCE16;
				else if( imageSource->getDataType() == ImageIo::FLOAT32 && supportsTextureFloat )
					mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_LUMINANCE_ALPHA32F_ARB : GL_LUMINANCE32F_ARB;
				else
					mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_LUMINANCE_ALPHA : GL_LUMINANCE;
			break;
#else
			case ImageIo::CM_RGB:
				mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_RGBA : GL_RGB;
			break;
			case ImageIo::CM_GRAY:
				mObj->mInternalFormat = ( imageSource->hasAlpha() ) ? GL_LUMINANCE_ALPHA : GL_LUMINANCE;
			break;
			
#endif
			default:
				throw ImageIoExceptionIllegalColorModel();
			break;
		}
	}
	else {
		mObj->mInternalFormat = format.mInternalFormat;
	}

	// setup an appropriate dataFormat/ImageTargetTexture based on the image's color space
	GLint dataFormat;
	ImageIo::ChannelOrder channelOrder;
	bool isGray = false;
	switch( imageSource->getColorModel() ) {
		case ImageSource::CM_RGB:
			dataFormat = ( imageSource->hasAlpha() ) ? GL_RGBA : GL_RGB;
			channelOrder = ( imageSource->hasAlpha() ) ? ImageIo::RGBA : ImageIo::RGB;
		break;
		case ImageSource::CM_GRAY:
			dataFormat = ( imageSource->hasAlpha() ) ? GL_LUMINANCE_ALPHA : GL_LUMINANCE;
			channelOrder = ( imageSource->hasAlpha() ) ? ImageIo::YA : ImageIo::Y;
			isGray = true;
		break;
		default: // if this is some other color space, we'll have to punt and go w/ RGB
			dataFormat = ( imageSource->hasAlpha() ) ? GL_RGBA : GL_RGB;
			channelOrder = ( imageSource->hasAlpha() ) ? ImageIo::RGBA : ImageIo::RGB;
		break;
	}

	glGenTextures( 1, &mObj->mTextureID );
	glBindTexture( mObj->mTarget, mObj->mTextureID );

	glTexParameteri( mObj->mTarget, GL_TEXTURE_WRAP_S, format.mWrapS );
	glTexParameteri( mObj->mTarget, GL_TEXTURE_WRAP_T, format.mWrapT );
	glTexParameteri( mObj->mTarget, GL_TEXTURE_MIN_FILTER, format.mMinFilter );	
	glTexParameteri( mObj->mTarget, GL_TEXTURE_MAG_FILTER, format.mMagFilter );
	if( format.mMipmapping )
		glTexParameteri( mObj->mTarget, GL_GENERATE_MIPMAP, GL_TRUE );
	if( mObj->mTarget == GL_TEXTURE_2D ) {
		mObj->mMaxU = mObj->mMaxV = 1.0f;
	}
	else {
		mObj->mMaxU = (float)mObj->mWidth;
		mObj->mMaxV = (float)mObj->mHeight;
	}	

	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
	if( imageSource->getDataType() == ImageIo::UINT8 ) {
		shared_ptr<ImageTargetGLTexture<uint8_t> > target = ImageTargetGLTexture<uint8_t>::createRef( this, channelOrder, isGray, imageSource->hasAlpha() );
		imageSource->load( target );
		glTexImage2D( mObj->mTarget, 0, mObj->mInternalFormat, mObj->mWidth, mObj->mHeight, 0, dataFormat, GL_UNSIGNED_BYTE, target->getData() );
	}
	else if( imageSource->getDataType() == ImageIo::UINT16 ) {
		shared_ptr<ImageTargetGLTexture<uint16_t> > target = ImageTargetGLTexture<uint16_t>::createRef( this, channelOrder, isGray, imageSource->hasAlpha() );
		imageSource->load( target );		
		glTexImage2D( mObj->mTarget, 0, mObj->mInternalFormat, mObj->mWidth, mObj->mHeight, 0, dataFormat, GL_UNSIGNED_SHORT, target->getData() );
	
	}
	else {
		shared_ptr<ImageTargetGLTexture<float> > target = ImageTargetGLTexture<float>::createRef( this, channelOrder, isGray, imageSource->hasAlpha() );
		imageSource->load( target );		
		glTexImage2D( mObj->mTarget, 0, mObj->mInternalFormat, mObj->mWidth, mObj->mHeight, 0, dataFormat, GL_FLOAT, target->getData() );
	}
}