-- Plugin developped by kichetof for Magic Lantern local LrTasks = import 'LrTasks' local LrApplication = import 'LrApplication' local LrLogger = import 'LrLogger' local LrErrors = import 'LrErrors' local LrProgressScope = import 'LrProgressScope' local LrDialogs = import 'LrDialogs' local LrPathUtils = import 'LrPathUtils' local mlLog = LrLogger('MLDualISO') mlLog:enable("print") exportServiceProvider = {} exportServiceProvider.canExportVideo = false -- Basename function -- Copyright 2011-2014, Gianluca Fiore © --- Function equivalent to basename in POSIX systems --@param str the path string function basename(str) local name = string.gsub(str, "(.*/)(.*)", "%2") return name end function delete(...) local rm = MAC_ENV == true and 'exec rm ' or 'start /B cmd.exe /c del /F /Q' for i,j in pairs({...}) do rm = string.format('%s "%s"', rm, j) end return rm end function existFile(filename) local f = io.open(filename,"r") if f ~= nil then io.close(f) return true else return false end end function exportServiceProvider.processRenderedPhotos(functionContext, exportContext) local exportSession = exportContext.exportSession local exportSettings = exportContext.propertyTable local nPhotos = exportSession:countRenditions() local progressScope = exportContext:configureProgress { title = nPhotos > 1 and LOC("$$$/ML/Publish/Progress=Exporting ^1 photos to cr2hdr", nPhotos) or LOC "$$$/ML/Publish/Progress/One=Exporting one photo to cr2hdr", } for i, rendition in exportContext:renditions { stopIfCanceled = true } do local fmt = rendition.photo:getRawMetadata("fileFormat") if fmt == "RAW" or fmt == "DNG" then progressScope:setPortionComplete((i - 1) / nPhotos) if not rendition.wasSkipped then local success, pathOrMessage = rendition:waitForRender() progressScope:setPortionComplete((i - 0.5) / nPhotos) -- original filename to export (exemple img_1234.cr2) local originalName = basename(rendition.photo.path) -- export path & filename (exemple ~/images/dualiso_1234.cr2) local filePath = assert(pathOrMessage) -- export path & filename for DNG file local filePathDNG = LrPathUtils.replaceExtension(filePath, "DNG") -- export path & filename for txt output command local output = LrPathUtils.replaceExtension(filePath, "txt") -- export path & filename for xmp file local filePathXmp = LrPathUtils.replaceExtension(filePath, "xmp") if not existFile(filePathDNG) or fmt == "DNG" then if progressScope:isCanceled() then break end if success then -- plugin path local pluginPath = _PLUGIN.path if MAC_ENV then -- cr2hdr exec path for Mac (& force language to english; seem to be unnecessary LANG=C LC_ALL=C LANGUAGE=en) command = string.format('exec "%s/bin/cr2hdr" "%s" > "%s"', pluginPath, filePath, output) else command = string.format('"start /D "%s\\bin" /B /WAIT /BELOWNORMAL cr2hdr.exe "%s" ^> "%s""', pluginPath, filePath, output) end result = LrTasks.execute(command) if result == 0 then -- remove dualiso_xxxx.cr2 & dualiso_xxxx.xmp not needed after convert, only dng file is necessary if fmt == "DNG" then cmd = delete(filePathXmp) else cmd = delete(filePath, filePathXmp) end LrTasks.execute(cmd) --if isFileExist then, import dualiso_xxxx.dng and stack with original file and set label if existFile(filePathDNG) then local catalog = LrApplication:activeCatalog() local importDualiso = catalog:withWriteAccessDo('Import from ML DualISO', function(context) catalog:addPhoto(filePathDNG, rendition.photo, 'above') local photo = catalog:findPhotoByPath(filePathDNG) photo:setRawMetadata('label', 'DualISO') end, {timeout = 30} ) if importDualiso ~= "executed" then LrDialogs.message (LOC "$$$/ML/Import/ErrorTitle=~ There was a problem ~", LOC"$$$/ML/Import/Error=Unable to import the dual iso file!^n^nPlease manually synchronise your folder") end else cmd = delete(output) LrTasks.execute(cmd) LrDialogs.message(LOC "$$$/ML/Publish/noDualIsoTitle=Doesn't look like interlaced ISO", LOC("$$$/ML/Publish/noDualIso=The image ^1 does not appear to be dual iso", originalName)) end else -- remove dualiso_xxxx.cr2 & dualiso_xxxx.xmp cmd = delete(filePath, filePathXmp) LrTasks.execute(cmd) LrDialogs.message(LOC "$$$/ML/Publish/Error/Title=Error to export", LOC("$$$/ML/Publish/Error=Unable to export ^1 to cr2hdr!^r^rError #^2^r^rReport it to MagicLantern Forum^n(don't forget to indicate this error number)", originalName, result), "critical") -- end if cr2hdr end -- end if success end else cmd = delete(filePath, filePathXmp) LrTasks.execute(cmd) LrDialogs.message(LOC "$$$/ML/Publish/AlreadyConvertTitle=Already treated", LOC("$$$/ML/Publish/AlreadyConvert=The file ^1 has already converted to dual iso", originalName)) end -- end if skipped end else LrDialogs.message(LOC "$$$/ML/Publish/Error/NotRawTitle=Wrong format", LOC "$$$/ML/Publish/Error/NotRaw=Only RAW photo is allowed to export to cr2hdr") -- end if not raw end -- end for end progressScope:done() -- end function end return exportServiceProvider