UFRaw + Hugin = batch converter +HDR (Win)

Plug-ins, add-ons, skins, icons, templates and other downloads. Contributions are welcome.

Moderators: XnTriq, xnview

Post Reply
barmale
Posts: 1
Joined: Mon Aug 29, 2011 5:38 am

UFRaw + Hugin = batch converter +HDR (Win)

Post by barmale » Mon Aug 29, 2011 6:32 am

MS-Windows
Script makes batch convert *.ufraw files
Also can makes HDR image from RAW file. Don't need use "Auto Bracketing" and shoot 3 times by camera.
*************************
Usage:
Create UFRaw ID file instead jpg (UFRaw - Save settings - Create ID file = Only) with preffered settings (Crop, rotate, wite balance, etc.).
1. Run script by drag and drop any file from directory with UFRaw id files (*.ufraw)
2. Register script in XnView - Tools - Options - New Interface command. You can run it by selecting any file in XnView and clicking button. My choise :)
*************************
Dependencies:
UFRaw (ufraw-batch.exe)
Hugin (enfuse.exe)
*************************
Customisation:
Change EXP_VAL for HDR dark and light images. "Auto Bracketing"
*************************
HDR_batch.vbs

Code: Select all

' First argument is any file path. Used only directory path
' Be free on change :)
' (C) XnView user
const UFRAW_S = "C:\Program Files\GIMP-2.0\bin\ufraw-batch.exe"
const ENFUSE = "C:\Program Files\Hugin\bin\enfuse.exe"
const EXP_VAL = 1

Dim objFSO
Dim oShell

call Main

Sub Main
	Dim objFolder, objFile
	Dim imagePath, imFolder
	'Check script arguments 
	if WScript.Arguments.Count = 0 then
		WScript.Echo "Specify path!"
		exit sub
	end if
	Set oShell = CreateObject("WScript.Shell")
	set objFSO = CreateObject("Scripting.FileSystemObject")
	'Extract current script directory (used as TMP folder)
	oShell.CurrentDirectory = objFSO.GetParentFolderName(Wscript.ScriptFullName)
	imagePath = WScript.Arguments.Item(0)
	Set objFile = objFSO.GetFile(imagePath)
	'Extract directory path
	imFolder = objFSO.GetParentFolderName(objFile) 
	'Ask user
	Dim MyVar
	MyVar = MsgBox ("All Images will be rewrited!!"& Chr(13) & "Yes - create normal and HDR images." & Chr(13) & "No - Only normal Images." & Chr(13) & "Cancel?", 3, "Batch HDR UFRaw converter!")
	if MyVar=2 then
		Exit Sub
	End If
	If MyVar=6 then
		ProcessFilesHDR(imFolder)
	else
		ProcessFiles(imFolder)
	End If
	
End Sub

'Create 3 images with different exposure and process them as HDR
Sub CreateHDRImage (ByVal sPath, ByVal sFile)
	Dim outFile
	outFile = sPath & "\" & sFile & ".jpg"	
	idFile =  sPath & "\" & sFile & ".ufraw"
	'Create default (0.jpg) image based on user settings
	Run("""" & UFRAW_S & """ --create-id=also --out-type=jpeg --output=0.jpg """ & idFile & """")
	'Create 2 (1.ufraw and 2.ufraw) ID files with different exp. values (see EXP_VAL const)
	if ChangeExposure("0.ufraw") then
		Run("""" & UFRAW_S & """ --out-type=jpeg --output=1.jpg 1.ufraw")
		Run("""" & UFRAW_S & """ --out-type=jpeg --output=2.jpg 2.ufraw")
	else
		'If "UFRaw/Exposure" node not found, used command line parameters
		Run("""" & UFRAW_S & """ --out-type=jpeg --exposure=-" & EXP_VAL & " --output=1.jpg 0.ufraw")
		Run("""" & UFRAW_S & """ --out-type=jpeg --exposure=" & EXP_VAL & " --output=2.jpg 0.ufraw")
	end if
	'Run "enfuse.exe" from Hugin project
	Run("""" & ENFUSE & """ --output=""" & sPath & "\" & sFile & "_HDR.jpg"" 0.jpg 1.jpg 2.jpg")
	'Copy and rename file created with user parameters
	'Comment next if case, if you want only HDR image
	If not objFSO.FileExists(outFile) Then
		objFSO.MoveFile "0.jpg", outFile
	End If
	'Delete TMP files
	Del("1.jpg")
	Del("2.jpg")
	Del("0.ufraw")
	Del("1.ufraw")
	Del("2.ufraw")
	'Delete UFRaw ID file
	Del(idFile)
End Sub


'Load UFRaw ID file as XML and change node value
Function ChangeExposure(ByVal sFile)
	Dim expValue
	
	Set objXMLDoc = CreateObject("Microsoft.XMLDOM") 
	objXMLDoc.async = False 
	objXMLDoc.load(sFile) 
   
	For Each node in objXMLDoc.selectNodes("UFRaw/Exposure")
		expValue = CDbl(node.text)
		node.text = expValue+EXP_VAL
		objXMLDoc.save("1.ufraw")
		node.text = expValue-EXP_VAL
		objXMLDoc.save("2.ufraw")
		ChangeExposure = true
		exit Function
	Next
	ChangeExposure = false

End Function

'Create one image with user parameters
Sub CreateImage (ByVal sPath, ByVal sFile)
	Dim outFile
	outFile = sPath & "\" & sFile & ".jpg"
	outFile =  """" & outFile & """"
	idFile =  sPath & "\" & sFile & ".ufraw"	
	Run("""" & UFRAW_S & """ --out-type=jpeg --overwrite --output=" & outFile & " """ & idFile & """")
	Del(idFile)
End Sub

'Process all *.ufraw files in directory
Sub ProcessFilesHDR(ByVal sFolder)
	Set objFolder = objFSO.GetFolder(sFolder)
	For Each objFile In objFolder.Files
		if StrComp(LCase(objFSO.GetExtensionName(objFile)),"ufraw") = 0 then
			CreateHDRImage objFSO.GetParentFolderName(objFile), objFSO.GetBaseName(objFile)
		end if
	Next
End Sub

'Process all *.ufraw files in directory
Sub ProcessFiles(ByVal sFolder)
	Set objFolder = objFSO.GetFolder(sFolder)
	For Each objFile In objFolder.Files
		if StrComp(LCase(objFSO.GetExtensionName(objFile)),"ufraw") = 0 then
			CreateImage objFSO.GetParentFolderName(objFile), objFSO.GetBaseName(objFile)
		end if
	Next
End Sub

Sub Run(ByVal sFile)
	Dim shell		
	Set shell = CreateObject("WScript.Shell")
    shell.Run sFile, 1, true
    Set shell = Nothing
End Sub

Sub Del(ByVal sFile)
	If objFSO.FileExists(sFile) Then
		objFSO.DeleteFile sFile
   	End If
end sub

Post Reply