MagickCore  6.9.12-72
Convert, Edit, Or Compose Bitmap Images
 All Data Structures
monitor.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % M M OOO N N IIIII TTTTT OOO RRRR %
7 % MM MM O O NN N I T O O R R %
8 % M M M O O N N N I T O O RRRR %
9 % M M O O N NN I T O O R R %
10 % M M OOO N N IIIII T OOO R R %
11 % %
12 % %
13 % MagickCore Progress Monitor Methods %
14 % %
15 % Software Design %
16 % Cristy %
17 % December 1995 %
18 % %
19 % %
20 % Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
22 % %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
25 % %
26 % https://imagemagick.org/script/license.php %
27 % %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
33 % %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 
40 /*
41  Include declarations.
42 */
43 #include "magick/studio.h"
44 #include "magick/artifact.h"
45 #include "magick/image.h"
46 #include "magick/log.h"
47 #include "magick/monitor.h"
48 #include "magick/monitor-private.h"
49 #include "magick/pixel-private.h"
50 
51 /*
52  Static declarations.
53 */
54 static SemaphoreInfo
55  *monitor_semaphore = (SemaphoreInfo *) NULL;
56 
57 /*
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 % %
60 % %
61 % %
62 + M o n i t o r C o m p o n e n t G e n e s i s %
63 % %
64 % %
65 % %
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %
68 % MonitorComponentGenesis() instantiates the monitor component.
69 %
70 % The format of the MonitorComponentGenesis method is:
71 %
72 % MagickBooleanMonitor MonitorComponentGenesis(void)
73 %
74 */
75 MagickPrivate MagickBooleanType MonitorComponentGenesis(void)
76 {
77  if (monitor_semaphore == (SemaphoreInfo *) NULL)
78  ActivateSemaphoreInfo(&monitor_semaphore);
79  return(MagickTrue);
80 }
81 
82 /*
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 % %
85 % %
86 % %
87 + M o n i t o r C o m p o n e n t T e r m i n u s %
88 % %
89 % %
90 % %
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %
93 % MonitorComponentTerminus() destroy monitor component.
94 %
95 % The format of the MonitorComponentTerminus method is:
96 %
97 % void MonitorComponentTerminus(void)
98 %
99 */
100 MagickPrivate void MonitorComponentTerminus(void)
101 {
102  if (monitor_semaphore == (SemaphoreInfo *) NULL)
103  ActivateSemaphoreInfo(&monitor_semaphore);
104  LockSemaphoreInfo(monitor_semaphore);
105  UnlockSemaphoreInfo(monitor_semaphore);
106  DestroySemaphoreInfo(&monitor_semaphore);
107 }
108 
109 /*
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 % %
112 % %
113 % %
114 % S e t I m a g e P r o g r e s s %
115 % %
116 % %
117 % %
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 %
120 % SetImageProgress() calls the monitoring callback with the progress of an
121 % image processing operation. It also sets the `monitor:progress` image
122 % artifact available with GetImageArtifact().
123 %
124 % The format of the SetImageProgress method is:
125 %
126 % MagickBooleanType SetImageProgress(const char *text,
127 % const MagickOffsetType offset,const MagickSizeType extent)
128 %
129 % A description of each parameter follows:
130 %
131 % o image: the image.
132 %
133 % o text: description of the image processing operation.
134 %
135 % o offset: the offset relative to the extent parameter.
136 %
137 % o extent: the extent of the progress.
138 %
139 */
140 MagickExport MagickBooleanType SetImageProgress(const Image *image,
141  const char *tag,const MagickOffsetType offset,const MagickSizeType extent)
142 {
143  char
144  message[MagickPathExtent];
145 
146  MagickBooleanType
147  status;
148 
149  if (image->progress_monitor == (MagickProgressMonitor) NULL)
150  return(MagickTrue);
151  (void) FormatLocaleString(message,MagickPathExtent,"%s/%s",
152  tag == (const char *) NULL ? "null" : tag,image->filename);
153  if (monitor_semaphore == (SemaphoreInfo *) NULL)
154  ActivateSemaphoreInfo(&monitor_semaphore);
155  LockSemaphoreInfo(monitor_semaphore);
156  status=image->progress_monitor(message,offset,extent,image->client_data);
157  (void) FormatLocaleString(message,MagickPathExtent,"%g%%:%s:%s",
158  (100.0*offset*PerceptibleReciprocal(extent-1.0)),
159  tag == (const char *) NULL ? "null" : tag,image->filename);
160  (void) SetImageArtifact((Image *) image,"monitor:progress",message);
161  UnlockSemaphoreInfo(monitor_semaphore);
162  return(status);
163 }
164 
165 /*
166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 % %
168 % %
169 % %
170 % S e t I m a g e P r o g r e s s M o n i t o r %
171 % %
172 % %
173 % %
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 %
176 % SetImageProgressMonitor() sets the image progress monitor to the specified
177 % method and returns the previous progress monitor if any. The progress
178 % monitor method looks like this:
179 %
180 % MagickBooleanType MagickProgressMonitor(const char *text,
181 % const MagickOffsetType offset,const MagickSizeType extent,
182 % void *client_data)
183 %
184 % If the progress monitor returns MagickFalse, the current operation is
185 % interrupted.
186 %
187 % The format of the SetImageProgressMonitor method is:
188 %
189 % MagickProgressMonitor SetImageProgressMonitor(Image *image,
190 % const MagickProgressMonitor progress_monitor,void *client_data)
191 %
192 % A description of each parameter follows:
193 %
194 % o image: the image.
195 %
196 % o progress_monitor: Specifies a pointer to a method to monitor progress of
197 % an image operation.
198 %
199 % o client_data: Specifies a pointer to any client data.
200 %
201 */
202 MagickExport MagickProgressMonitor SetImageProgressMonitor(Image *image,
203  const MagickProgressMonitor progress_monitor,void *client_data)
204 {
205  MagickProgressMonitor
206  previous_monitor;
207 
208  previous_monitor=image->progress_monitor;
209  image->progress_monitor=progress_monitor;
210  image->client_data=client_data;
211  return(previous_monitor);
212 }
213 
214 /*
215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 % %
217 % %
218 % %
219 % S e t I m a g e I n f o P r o g r e s s M o n i t o r %
220 % %
221 % %
222 % %
223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 %
225 % SetImageInfoProgressMonitor() sets the image_info progress monitor to the
226 % specified method and returns the previous progress monitor if any. The
227 % progress monitor method looks like this:
228 %
229 % MagickBooleanType MagickProgressMonitor(const char *text,
230 % const MagickOffsetType offset,const MagickSizeType extent,
231 % void *client_data)
232 %
233 % If the progress monitor returns MagickFalse, the current operation is
234 % interrupted.
235 %
236 % The format of the SetImageInfoProgressMonitor method is:
237 %
238 % MagickProgressMonitor SetImageInfoProgressMonitor(ImageInfo *image_info,
239 % const MagickProgressMonitor progress_monitor,void *client_data)
240 %
241 % A description of each parameter follows:
242 %
243 % o image_info: the image info.
244 %
245 % o progress_monitor: Specifies a pointer to a method to monitor progress of
246 % an image operation.
247 %
248 % o client_data: Specifies a pointer to any client data.
249 %
250 */
251 MagickExport MagickProgressMonitor SetImageInfoProgressMonitor(
252  ImageInfo *image_info,const MagickProgressMonitor progress_monitor,
253  void *client_data)
254 {
255  MagickProgressMonitor
256  previous_monitor;
257 
258  previous_monitor=image_info->progress_monitor;
259  image_info->progress_monitor=progress_monitor;
260  image_info->client_data=client_data;
261  return(previous_monitor);
262 }
Definition: image.h:152