コード例 #1
0
ファイル: OpenNI2Camera.cpp プロジェクト: hksonngan/cvt
 static void copyRGB( Image& dst, const uint8_t* p, size_t pStride )
 {
     IMapScoped<uint8_t> map( dst );
     size_t h = dst.height();
     SIMD* simd = SIMD::instance();
     size_t n = dst.width() * 3;
     while( h-- ){
         simd->Conv_XXXu8_to_XXXAu8( map.ptr(), p, n );
         map++;
         p += pStride;
     }
 }
コード例 #2
0
ファイル: TGALoader.cpp プロジェクト: Shorkaa/cvt
/*
   Supported combinations of depth and attribute-bits:

   Depth   Attribute-Bits
   ----------------------
   48	    0	TODO
   32	    8
   32	    0
   24	    0
   16	    1	TODO
   16	    0	TODO
   15	    0	TODO
 */
static void tga_decode_color( Image& img, FILE* file, TGAHeader* header, TGAExtension* ext )
{
	uint8_t* dst;
	uint8_t* pdst;
	size_t stride;
	size_t height;
	ssize_t sstride;
	size_t read;
	size_t dataoffset;
	IFormat format( IFormat::BGRA_UINT8 ); // Assume BGRA_UINT8
	uint8_t alphabits = header->desc & TGA_ALPHABIT_MASK;

	/*seek to data*/
	dataoffset = TGA_HEADER_SIZE + header->idlength;
	if( fseek( file, dataoffset, SEEK_SET ) < 0 )
		throw CVTException( "Corrupted TGA file! " );

	if( header->depth == 32 &&  ( alphabits == 8 || alphabits == 0 ) ) {
		/* Extension area available */
		if( ext ) {
			if( ext->attributes == 3 || ext->attributes == 4 /* FIXME: premultiplied*/ )
				format = IFormat::BGRA_UINT8;
			else
				throw CVTException( "Unsupported TGA file!" );
		}

		img.reallocate( header->width, header->height, format );
		dst = img.map( &stride );
		height = header->height;
		sstride = stride;

		pdst = ( uint8_t* ) tga_origin( header, dst, &sstride );

		while( height-- ) {
			if( ( read = fread( pdst, sizeof( uint32_t ), header->width, file ) ) != header->width )
				throw CVTException( "Corrupted TGA file!" );
			// FIXME: set arbitrary alpha to 1
/*			if( !alphabits )
				ziutil_xxxa_to_xxx1_ub( dst, dst, header->width );*/
			pdst += sstride;
		}
		img.unmap( dst );
	} else if( header->depth == 24 && alphabits == 0 ) {
		img.reallocate( header->width, header->height, IFormat::BGRA_UINT8 );
		dst = img.map( &stride );
		height = header->height;
		sstride = stride;
		pdst = ( uint8_t* ) tga_origin( header, dst, &sstride );
		//uint8_t* buffer = new uint8_t[ header->width * 3 ];
		ScopedBuffer<uint8_t,true> buffer( header->width * 3 );
		SIMD* simd = SIMD::instance();

		while( height-- ) {
			if( ( read = fread( buffer.ptr(), sizeof( uint8_t ), header->width * 3, file ) ) != ( size_t ) header->width * 3 )
				throw CVTException( "Corrupted TGA file!" );
			simd->Conv_XXXu8_to_XXXAu8( pdst, buffer.ptr(), header->width * 3 );
			pdst += sstride;
		}
		img.unmap( dst );
	} else {
		throw CVTException( "Unsupported TGA file!" );
	}
}