Exemplo n.º 1
0
int main(int argc, char* argv[])
{

	CmdLine cmd("hdr2png - convert radiance RGBE to png RGBA", ' ', "0.1");

	ValueArg<string> a_input("i","input","input hdr file",true,"","string", cmd );
	ValueArg<string> a_output("o","output","output png file",true,"","string", cmd );
	
	SwitchArg a_rebase("r","rebase", "maximize exponent range", true);
	cmd.add( a_rebase );

	cmd.parse( argc, argv );
	
	const char* input = a_input.getValue().c_str();
	const char* output = a_output.getValue().c_str();
	
	const bool rebase = a_rebase.getValue();

	//==================================================
	//								       Load hdr file
	//==================================================

	HDRLoaderResult* hdrData = new HDRLoaderResult();

	HDRLoader* hdrLoader = new HDRLoader();
	if( ! hdrLoader->load( input, *hdrData ) ) {
		printf( "error loading %s \n", input );
		return 1;
	}

	printf( "input loaded \n   size : %i*%i \n   range %i>%i \n", hdrData->width, hdrData->height , hdrData->eMin, hdrData->eMax );
	
	double base;
	if( rebase ) 
		base = getNewBase(  hdrData->eMin, hdrData->eMax );
	else
		base = 2.0f;


	
	printf( "f32toRgbe (base : %f)\n", base );
	const unsigned char* rgbe = f32toRgbe( hdrData->cols, hdrData->width, hdrData->height, base );

	printf( "encode png \n" );
	/*Encode the image*/
	unsigned error = lodepng_encode32_file( output, rgbe, hdrData->width, hdrData->height );

	/*if there's an error, display it*/
	if(error) printf("error %u: %s \n", error, lodepng_error_text(error));


	delete hdrLoader;
	delete hdrData;


	return 0;
}
Exemplo n.º 2
0
int main(int argc, char* argv[])
{

	int faceSize;

	CmdLine cmd("diffusefilter - generate blured cube map", ' ', "0.1");

	ValueArg<string> a_input("i","input","input raw cube texture",true,"","string", cmd );
	ValueArg<string> a_output("o","output","output raw file",true,"","string", cmd );
	
    ValueArg<float> a_power("p","power","fresnel power",false,1.0,"float", cmd );
    ValueArg<float> a_curve("c","curve","dot curve",false,1.0,"float", cmd );
    ValueArg<float> a_mix("m","mix","dot curve",false,0.0,"float", cmd );
	ValueArg<int> a_size("s","size","output size",false,64,"int", cmd );
	
	SwitchArg a_rebase("r","rebase", "maximize exponent range", true);
	cmd.add( a_rebase );

	cmd.parse( argc, argv );
	
	const char* input = a_input.getValue().c_str();
	const char* output = a_output.getValue().c_str();
	
    const float power = a_power.getValue();
    const float curve = a_curve.getValue();
    const float mix = a_mix.getValue();
	int size = a_size.getValue();
	const bool rebase = a_rebase.getValue();

	

	if( ! IsPowerOfTwo( size ) ) {
		printf( "error - output size %i must be POT", size );
		return 2;
	}
	
	printf( "blurring input cube texture \n    input %s \n    output %s \n" ,  input, output );


	//==================================================
	//								       Load hdr file
	//==================================================

	HDRLoaderResult* hdrData = new HDRLoaderResult();

	HDRLoader* hdrLoader = new HDRLoader();
	if( ! hdrLoader->load( input, *hdrData ) ) {
		printf( "error loading %s \n", input );
		return 1;
	}

	faceSize = hdrData->height/4;

	printf( "input loaded \n   size : %i*%i \n   range %i>%i \n", hdrData->width, hdrData->height , hdrData->eMin, hdrData->eMax );
	
	double base;
	if( rebase ) 
		base = getNewBase(  hdrData->eMin, hdrData->eMax );
	else
		base = 2.0f;

	//==================================================
	//								       extract faces
	//==================================================

	int mlevel = 1;

	printf( "splitCrossmap \n" );
	float** faces = splitCrossmap( hdrData );


	
	//==================================================
	//								       process blur
	//==================================================

	int rescaleMul = -1; // subscale source to have source double size of output
	
	int mip = getMipForSize( size, faceSize ) - rescaleMul;

	if( mip > 0 ) {
		float** sfaces = subscaleFaces( faces, faceSize, faceSize, mip );
		faceSize = faceSize >> mip;

		for (int j = 0; j < 6; ++j ) 
			free( faces[j] );
		free( faces );

		faces = sfaces;
	}