コード例 #1
0
ファイル: qtienc.c プロジェクト: 50m30n3/QTC
int main( int argc, char *argv[] )
{
	struct image image;
	struct qti compimage;
	struct tilecache *cache;

	int opt, verbose;
	unsigned long int insize, bsize, outsize;
	unsigned long int cacheblocks, cachehits;
	int transform, colordiff;
	int rangecomp;
	int minsize;
	int maxdepth;
	int lazyness;
	int cachesize;
	char *infile, *outfile;

	verbose = 0;
	transform = 0;
	colordiff = 0;
	rangecomp = 0;
	minsize = 2;
	maxdepth = 16;
	cachesize = 0;
	lazyness = 0;
	infile = NULL;
	outfile = NULL;

	while( ( opt = getopt( argc, argv, "hevy:t:s:d:c:l:i:o:" ) ) != -1 )
	{
		switch( opt )
		{
			case 'h':
				print_help();
				return 0;
			break;

			case 't':
				if( sscanf( optarg, "%i", &transform ) != 1 )
					fputs( "main: Can not parse command line: -t\n", stderr );
			break;

			case 'e':
				rangecomp = 1;
			break;

			case 'y':
				if( sscanf( optarg, "%i", &colordiff ) != 1 )
					fputs( "main: Can not parse command line: -y\n", stderr );
			break;

			case 'v':
				verbose = 1;
			break;

			case 's':
				if( sscanf( optarg, "%i", &minsize ) != 1 )
					fputs( "main: Can not parse command line: -s\n", stderr );
			break;

			case 'd':
				if( sscanf( optarg, "%i", &maxdepth ) != 1 )
					fputs( "main: Can not parse command line: -d\n", stderr );
			break;

			case 'c':
				if( sscanf( optarg, "%i", &cachesize ) != 1 )
					fputs( "main: Can not parse command line: -c\n", stderr );
			break;

			case 'l':
				if( sscanf( optarg, "%i", &lazyness ) != 1 )
					fputs( "main: Can not parse command line: -l\n", stderr );
			break;

			case 'i':
				infile = strdup( optarg );
			break;

			case 'o':
				outfile = strdup( optarg );
			break;

			default:
			case '?':
				fputs( "main: Can not parse command line: unknown option\n", stderr );
				return 1;
			break;
		}
	}

	if( ( transform < 0 ) || ( transform > 2 ) )
	{
		fputs( "main: Transform mode out of range\n", stderr );
		return 1;
	}

	if( ( colordiff < 0 ) || ( colordiff > 2 ) )
	{
		fputs( "main: Fakeyuv mode out of range\n", stderr );
		return 1;
	}

	if( minsize < 0 )
	{
		fputs( "main: Mininmal block size out of range\n", stderr );
		return 1;
	}

	if( maxdepth < 0 )
	{
		fputs( "main: Maximum recursion depth out of range\n", stderr );
		return 1;
	}

	if( cachesize < 0 )
	{
		fputs( "main: Cache size out of range\n", stderr );
		return 1;
	}

	if( lazyness < 0 )
	{
		fputs( "main: Lazyness recursion depth out of range\n", stderr );
		return 1;
	}

	if( ! ppm_read( &image, infile ) )		// Read the input image
		return 2;

	insize = image.width * image.height * 3;

	if( colordiff >= 1 )		// Apply fakeyuv transform
		image_color_diff( &image );

	if( transform == 1 )		// Apply image transforms
		image_transform_fast( &image );
	else if( transform == 2 )
		image_transform( &image );

	if( cachesize > 0 )
		cache = tilecache_create( cachesize*1024, minsize );		// Create tile cache
	else
		cache = NULL;

	if( ! qti_create( &compimage, image.width, image.height, minsize, maxdepth, cache ) )
		return 2;

	if( ! qtc_compress( &image, NULL, &compimage, lazyness, colordiff >= 2 ) )		// Compress the image
		return 2;

	bsize = qti_getsize( &compimage );

	if( ! ( outsize = qti_write( &compimage, rangecomp, outfile ) ) )		// Write image to file
		return 2;
	
	image_free( &image );
	qti_free( &compimage );
	
	if( cache != NULL )
	{
		cacheblocks = cache->numblocks;
		cachehits = cache->hits;
		tilecache_free( cache );
	}
	else
	{
		cacheblocks = 0;
		cachehits = 0;
	}
	
	if( verbose )
		fprintf( stderr, "In:%luB Buff:%luB,%f%% Cache:%lu/%lu,%f%% Out:%luB,%f%%\n",
		         insize, bsize/8, (bsize/8)*100.0/insize,
		         cachehits, cacheblocks, cachehits*100.0/cacheblocks,
		         outsize, outsize*100.0/insize );

	free( infile );
	free( outfile );

	return 0;
}
コード例 #2
0
ファイル: frame_transform.cpp プロジェクト: CasparCG/Server
image_transform image_transform::operator*(const image_transform& other) const
{
    return image_transform(*this) *= other;
}