@@ -31,7 +31,7 @@ local mogrifyPath
31
31
32
32
--[[
33
33
-- Call mogrify with 'params'
34
- -- Raises a LrError in case of an execution error
34
+ -- Raises a LrError in case of an execution error
35
35
--]]
36
36
local function mogrifyExecute (params , script )
37
37
if mogrifyPath == nil then
@@ -44,15 +44,15 @@ local function mogrifyExecute(params, script)
44
44
local cmdline = ' \" ' .. mogrifyPath .. ' \" '
45
45
if script then
46
46
scriptName = createMagickScript (params )
47
- cmdline = cmdline .. ' -script ' .. ' \" ' .. scriptName .. ' \" '
47
+ cmdline = cmdline .. ' -script ' .. ' \" ' .. scriptName .. ' \" '
48
48
else
49
49
cmdline = cmdline .. ' mogrify ' .. params
50
50
end
51
- logDebug (' mogrifyExecute' , cmdline )
51
+ logDebug (' mogrifyExecute' , cmdline )
52
52
local stat = LrTasks .execute ( ' \" ' .. cmdline .. ' \" ' )
53
53
if stat ~= 0 then
54
- logError (' mogrifyDraw' , ' Error calling: ' .. cmdline )
55
- LrErrors .throwUserError (" Error calling 'mogirfy .exe' Please check plugin configuration" )
54
+ logError (' mogrifyDraw' , ' Error calling: ' .. cmdline )
55
+ LrErrors .throwUserError (" Error calling 'mogrify .exe' Please check plugin configuration" )
56
56
end
57
57
if script then
58
58
local prefs = LrPrefs .prefsForPlugin ( nil )
@@ -61,39 +61,57 @@ local function mogrifyExecute(params, script)
61
61
LrFileUtils .delete (scriptName )
62
62
end
63
63
end
64
-
65
- end
66
64
65
+ end
67
66
68
67
69
68
--[[
70
69
-- Export the catalog photo to disk
71
70
-- photo: Lr catalog photo
72
71
-- xSize: width in pixel of the create temporary photo
73
72
-- ySize: height in pixel of the create temporary photo
74
- --
73
+ --
75
74
-- requestJpegThumbnail treats the size as minimum value, thus the image on the disk maybe larger
75
+ --
76
+ -- Note: in LrC 14 (at least on WIN) this function fails on the first call for an image.
77
+ -- Analysis and proposal for a fix by John R. Ellis (LR SDK luminary on Adobe forums):
78
+ --
79
+ -- requestJpegThumbnail() appears to call the callback synchronously if the requested thumbnail
80
+ -- is in an internal cache. Otherwise, it returns immediately and calls the callback asynchronously
81
+ -- after the thumbnail is generated and loaded into the cache, which could take anywhere from
82
+ -- 0.01 seconds to a couple seconds if the photo has to be re-rendered.
83
+ -- In order to make sure the thumbnail has been written to file before proceeding with the next
84
+ -- steps, exportToDisk() should busy wait until the callback is invoked.
85
+ -- photo:getRawMetadata() has to be executed outside the callback, because this method "yields"
86
+ -- which is not allowed in a no-yielding context (asynchronous call of callback)
76
87
--]]
77
88
local function exportToDisk (photo , xSize , ySize )
89
+ local done = false
90
+ local orgPath = photo :getRawMetadata (" path" )
78
91
local thumb = photo :requestJpegThumbnail (xSize , ySize , function (data , errorMsg )
79
92
if data == nil then
80
93
logError (' exportToDisk' , ' No thumbnail data' )
81
94
LrErrors .throwUserError (" Export to disk failed. No thumbnail data received." )
82
95
else
83
- local orgPath = photo :getRawMetadata (" path" )
84
96
local leafName = LrPathUtils .leafName ( orgPath )
85
97
local leafWOExt = LrPathUtils .removeExtension ( leafName )
86
98
local tempPath = LrPathUtils .getStandardFilePath ( " temp" )
87
99
fileName = LrPathUtils .child ( tempPath , leafWOExt .. " -fpoints.jpg" )
88
- logDebug (' exportToDisk' , " filename = " .. fileName )
100
+ logDebug (' exportToDisk' , " filename = " .. fileName )
89
101
90
102
local localFile = io.open (fileName , " w+b" )
91
103
localFile :write (data )
92
104
localFile :close ()
93
105
end
106
+ done = true
94
107
end )
108
+ if not done then
109
+ -- busy wait for (asynchronous) callback to complete
110
+ while not done do LrTasks .sleep (0.1 ) end
111
+ end
95
112
end
96
113
114
+
97
115
--[[
98
116
-- Resize the disk image to the given ize
99
117
-- xSize: width in pixel
@@ -118,26 +136,26 @@ local function mapIconToStrokewidthAndColor(name)
118
136
end
119
137
120
138
--[[
121
- -- Build the mogirfy draw parameters base on the focuspointsTable
139
+ -- Build the mogrify draw parameters base on the focuspointsTable
122
140
--]]
123
141
local function buildDrawParams (focuspointsTable )
124
- local para = nil
125
- local sw = nil
126
- local color = nil
127
-
142
+ local para
143
+ local sw
144
+ local color
145
+
128
146
local params = ' -fill none '
129
147
for i , fpPoint in ipairs (focuspointsTable ) do
130
148
if fpPoint .template .center ~= nil then
131
- local x = math.floor (tonumber (fpPoint .points .center .x ))
149
+ local x = math.floor (tonumber (fpPoint .points .center .x ))
132
150
local y = math.floor (tonumber (fpPoint .points .center .y ))
133
151
para = ' -stroke red -fill red -draw \" circle ' .. x .. ' ,' .. y .. ' ' .. x + 3 .. ' ,' .. y .. ' \" -fill none '
134
- logDebug (' buildCmdLine' , ' [' .. i .. ' ] ' .. para )
152
+ logDebug (' buildCmdLine' , ' [' .. i .. ' ] ' .. para )
135
153
params = params .. para
136
154
end
137
155
if fpPoint .template .corner ~= nil then
138
156
sw , color = mapIconToStrokewidthAndColor (fpPoint .template .corner .fileTemplate )
139
157
para = ' -strokewidth ' .. sw .. ' -stroke ' .. color .. ' '
140
- local tlx = math.floor (tonumber (fpPoint .points .tl .x ))
158
+ local tlx = math.floor (tonumber (fpPoint .points .tl .x ))
141
159
local tly = math.floor (tonumber (fpPoint .points .tl .y ))
142
160
local brx = math.floor (tonumber (fpPoint .points .br .x ))
143
161
local bry = math.floor (tonumber (fpPoint .points .br .y ))
@@ -146,48 +164,48 @@ local function buildDrawParams(focuspointsTable)
146
164
local x = tlx
147
165
tlx = brx
148
166
brx = x
149
- end
150
- if fpPoint .rotation == 0 or fpPoint .rotation == 360 then
167
+ end
168
+ if fpPoint .rotation == 0 or fpPoint .rotation == 360 then
151
169
para = para .. ' -draw \" roundRectangle ' .. tlx .. ' ,' .. tly .. ' ' .. brx .. ' ,' .. bry .. ' 1,1\" '
152
170
else
153
171
local trx = math.floor (tonumber (fpPoint .points .tr .x ))
154
172
local try = math.floor (tonumber (fpPoint .points .tr .y ))
155
173
local blx = math.floor (tonumber (fpPoint .points .bl .x ))
156
174
local bly = math.floor (tonumber (fpPoint .points .bl .y ))
157
- para = para .. ' -draw \" polyline ' .. trx .. ' ,' .. try .. ' ' .. tlx .. ' ,' .. tly .. ' '
175
+ para = para .. ' -draw \" polyline ' .. trx .. ' ,' .. try .. ' ' .. tlx .. ' ,' .. tly .. ' '
158
176
.. blx .. ' ,' .. bly .. ' ' .. brx .. ' ,' .. bry .. ' ' .. trx .. ' ,' .. try .. ' \" '
159
177
end
160
- logDebug (' buildCmdLine' , ' [' .. i .. ' ] ' .. para .. ' ' .. fpPoint .template .corner .fileTemplate )
178
+ logDebug (' buildCmdLine' , ' [' .. i .. ' ] ' .. para .. ' ' .. fpPoint .template .corner .fileTemplate )
161
179
params = params .. para
162
180
end
163
181
end
164
182
return params
165
183
end
166
184
167
185
--[[
168
- -- Create a temprory disk impage for the given Lightroom catalog photo.
186
+ -- Create a temprory disk impage for the given Lightroom catalog photo.
169
187
-- photo: Lr catalog photo
170
188
-- xSize: width in pixel of the create temporary photo
171
189
-- ySize: height in pixel of the create temporary photo
172
190
--]]
173
191
function MogrifyUtils .createDiskImage (photo , xSize , ySize )
174
- logInfo (' MogrifyUtils.createDiskImage' , photo :getFormattedMetadata ( ' fileName' ) .. ' ' .. xSize .. ' ' .. ySize )
192
+ logInfo (' MogrifyUtils.createDiskImage' , photo :getFormattedMetadata ( ' fileName' ) .. ' ' .. xSize .. ' ' .. ySize )
175
193
exportToDisk (photo , xSize , ySize )
176
194
mogrifyResize (xSize , ySize )
177
195
return fileName
178
196
end
179
197
180
198
181
- --[[
199
+ --[[
182
200
-- Draw the focus poins bases on focuspointsTable (see 'DefaultPointRenderer.prepareRendering' for adescription of the table)
183
201
--]]
184
202
function MogrifyUtils .drawFocusPoints (focuspointsTable )
185
- local params = buildDrawParams (focuspointsTable )
203
+ local params = buildDrawParams (focuspointsTable )
186
204
mogrifyExecute (params , true )
187
205
end
188
206
189
207
190
- --[[
208
+ --[[
191
209
-- Creates a temporay script file for Magick. Returns the name of the temp file
192
210
--]]
193
211
function createMagickScript (params )
@@ -201,8 +219,8 @@ function createMagickScript(params)
201
219
end
202
220
203
221
204
- --[[
205
- -- Deletes the temporary file (created by 'MogrifyUtils.exportToDisk')
222
+ --[[
223
+ -- Deletes the temporary file (created by 'MogrifyUtils.exportToDisk')
206
224
-- Raises a LrError in case that the deletion fails
207
225
--]]
208
226
function MogrifyUtils .cleanup ()
0 commit comments