' ------------------------------------------------------------------------------------ ' Start_StereoPhotoMaker.vbs ' ' This script will launch the StereoPhoto Maker application. ' Two methods are used: ' - if only one picture is selected, it is assume that this picture is the left one ' and the next is the right picture. Offset information is written back in the ' "Offset" Custom Field of the right picture allowing the alignment done in ' StereoPhoto Maker to be stored in the album. ' - if more than two pictures are selected, a slideshow script is created with all ' the pairs of defined pictures and StereoPhoto Maker is started with this script. ' Caution: when started in "single picture" mode, MyAlbum will wait for the application ' to end (to retrieve the new picture offset) and seems to be frozen. Close first the ' StereoPhoto Maker application before returning to MyAlbum. ' ------------------------------------------------------------------------------------ Option Explicit 'Const spmPath = "D:\HTML\StereoScope\stphmkre.exe" ' Replace by the full path of the application Const spmPath = "M:\Images\Stéréo\stphmkre.exe" 'Const spmComment = "%C1 %C2" Const ForReading = 1, ForWriting = 2 const JPS_RATIO = 1.82 app.ClearTrace Dim alb, pic, pic1, pic2, sCmd, fso, f, outputFileName, s, T, xO, yO, xO2, yO2, bSinglePix, bJPS, nRunMode Set fso = CreateObject("Scripting.FileSystemObject") outputFileName = left( spmPath, InStrRev( spmPath, "\" ) ) & "spm.txt" set alb = app.GetCurrentAlbum bSinglePix = (alb.nbSelectedPicture <= 2) nRunMode = 3 if bSinglePix then set pic1 = alb.GetVisiblePicture( alb.nCurrentPicture ) set pic2 = alb.GetVisiblePicture( alb.nCurrentPicture+1 ) bJPS = CheckForJPS( pic1 ) app.Trace "JPS mode is: " & bJPS if not bJPS then GetPictureOffset pic2, xO, yO s = -xO & "," & yO app.Trace "Current offset = " & xO & "," & yO end if ' Build a pseudo-slideshow file for StereoPhoto Maker with a long delay (10 hours!) so we have time to ' work on the pictures. ' SPM doesn't use the same convention than MyAlbum and uses an inverted y-offset (and both ' x and y offsets are stored in the slideshow file with an inverted sign). Set f = fso.OpenTextFile( outputFileName, ForWriting, True ) if not bJPS then f.WriteLine "21,36000,0," & s & "," & alb.ExpandMacro( pic1, "%RP" ) & "," & alb.ExpandMacro( pic2, "%RP" ) & ",," nRunMode = &h10003 else s = "0,0" f.WriteLine "11,36000,0," & s & "," & alb.ExpandMacro( pic1, "%RP" ) & ",,," end if f.Close sCmd = spmPath & " " & outputFileName '"java -mx256m -ms64m -cp " & stereoscopePath & "\stereoscope.jar;" & stereoscopePath & " Stereoscope """ & alb.ExpandMacro( pic, "%RP" ) & """" 'app.Trace sCmd app.Run sCmd, False, nRunMode if not bJPS then Set f = fso.OpenTextFile( outputFileName, ForReading, True ) s = f.ReadLine f.Close T = Split( s, ",", -1, 1 ) xO2 = -CInt( T(3) ) yO2 = CInt( T(4) ) 'app.Trace xO & "," & yO 'app.Trace xO2 & "," & yO2 if xO <> xO2 or yO <> yO2 then s = xO2 & "," & yO2 app.Trace "New offset = " & s pic2.SetCustomField "Offset", s end if end if else ' Multiple pictures dim nbPic, i, iP, bFirstPic nbPic = alb.nbPicture iP = 0 bFirstPic = True Set f = fso.OpenTextFile( outputFileName, ForWriting, True ) for i = 0 to nbPic-1 Set pic = alb.GetPicture(i) if pic.bSelected then if bFirstPic then bJPS = CheckForJPS( pic ) app.Trace "JPS mode is: " & bJPS bFirstPic = False end if if iP = 0 and not bJPS then ' Wait to have a pair of pictures set pic1 = pic iP = 1 else if not bJPS then set pic2 = pic app.Trace "Processing left picture " & vbTab & pic1.sShortFileName & "...", -1, TRACE_INFORMATION app.Trace "Processing right picture" & vbTab & pic2.sShortFileName & "..." iP = 0 GetPictureOffset pic2, xO, yO s = -xO & "," & yO f.WriteLine "21,36000,0," & s & "," & alb.ExpandMacro( pic1, "%RP" ) & "," & alb.ExpandMacro( pic2, "%RP" ) & ",," else app.Trace "Processing JPS picture " & vbTab & pic.sShortFileName & "...", -1, TRACE_INFORMATION f.WriteLine "11,36000,0,0,0," & alb.ExpandMacro( pic, "%RP" ) & ",,," end if end if end if next f.close sCmd = spmPath & " " & outputFileName app.Run sCmd, False, nRunMode end if app.Trace "Done!", -1, TRACE_OK sub GetPictureOffset( byref pix, byref xP, byref yP) dim s, T if pix is Nothing then s = "" else s = pix.GetCustomField( "Offset" ) end if 'app.Trace "Current offset = " & s if s = "" then s = "0,0" T = Split( s, ",", -1, 1 ) xP = CInt(T(0)) yP = CInt(T(1)) end sub function CheckForJPS( byref pic ) ' A JPS picture (side-by-side) is generally much larger than usual ' so we guess if it's a JPS when the width is more than JPS_RATIO times the height CheckForJPS = False if LCase(right(pic.sShortFileName,4)) = ".jps" then CheckForJPS = TRUE elseif pic.w > pic.h * JPS_RATIO then CheckForJPS = TRUE end if end function