Return to the tutorials
Return to the scripting


HDR Shop Scripting - Panoramic Transfomations

One of the most popular features of HDRShop is the ability to easily convert between multiple panoramic formats. The basics of panoramic mappings is covered in the tutorial - Panoramic Image Transformations. This scripts covers how to access and extend this same functionality through your scripts.

Panoramic transform is simply a pixel sampling operation that sets pixels values according to several popular image-mapping equations. This could be implemented using just Javascript pixel access functions (mappings.js) but is extremely slow and is not recommended. Alternatively HDRShop provides a function for panoramic transforms as a memeber of the Image class.
void PanoramicResample(srcFormat, dstFormat, dstWidth, dstHeight, sampling, supersample, transform)
srcFormat and dstFormat are the integer ids of the the desired panoramic format. dstWidth and dstHeight represent the desired size of the destination image. sampling is an integer indicating the sampling technique. tranform is a string representing a 3d rotation that can be applied to the panorama. The tranformation can be either a combination of axis rotations and/or a rotation matrix following this format.

Here is a script that runs panoramicresample on a series of images in a directory (batchpanoramicresample.js)
var dlg = new Dialog("Panoramic resample script", 700, 200);

var types = new Array("bmp","jpg","ppm","tga","tif", "hdr", "pfm");

dlg.AddStatic("INPUT SETTINGS"); // 0
dlg.AddString("Directory", "c:\\"); // 1
dlg.AddChoice("File type", 4, types[0] + "|" + types[1] + "|" + types[2] + "|" + types[3] + "|" + types[4] + "|" + types[5] + "|" + types[6]); // 2
dlg.AddPanoramicFormat() // 3

dlg.AddStatic("OUTPUT SETTINGS"); // 4
dlg.AddString("Directory", "c:\\"); // 5

// this last line adds error checking so that the output panoramic format has the proper width and height.
dlg.EnsurePanoramicAspectRatio( dlg.AddPanoramicFormat(), dlg.AddInt("Width", 1024, 1), dlg.AddInt("Height", 512, 1), dlg.AddCheck("Keep Aspect Ratio", 1)); // 6, 7, 8, 9
dlg.AddChoice("Sampling", 2, "Nearest neighbor|Bilinear|Bicubic"); // 10
dlg.AddInt("Supersample", 3); // 11

var result = dlg.DoModal(); // create the window (similar to the MFC style DoModal function)

if (result == 1) // if the user clicked OK, process images
{
	// get all files ending with desired extension
	var path = dlg.GetString(1) + "*." + types[dlg.GetChoice(2)];
	var filelist = System.Files(path);

	// get other parameters from dialog
	var newpath = dlg.GetString(5);
	var inputformat = dlg.GetPanoramicFormat(3);
	var outputformat = dlg.GetPanoramicFormat(6);
	var width = dlg.GetInt(7);
	var height = dlg.GetInt(8);
	var sampling = dlg.GetChoice(10);
	var supersample = dlg.GetInt(11);
	
	// iterate through the file names	
	var processed = 0;
	while(processed < filelist.length)
	{
		var filename = filelist[processed];
		var img = LoadImage(filename);

		img.Rotate90CW(); // or use Rotate90CCW();
		img.FlipHorizontal(); // or use FlipVertical();

		// the optional matrix parameter allows you to apply a custom rotation during resampling (I only include it so you know its there)
		var img2 = img.PanoramicResample(inputformat, outputformat, width, height, sampling, supersample, { matrix:[1, 0, 0, 0, 1, 0, 0, 0, 1] }, {} );
		
		// change the path to the new output directory
		var newname = filename.replace(/^.*\\/, newpath);
		
		img2.Save(newname);
		
		Sleep(100);
		img.Close(1); // force the image to close
		img2.Close(1);
				
		processed++;
	}
	
	Alert("Processed " + processed + "  files ");
	
}


Return to the scripting
Return to the tutorials