MagickCore 7.1.1
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
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 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 "MagickCore/studio.h"
44#include "MagickCore/artifact.h"
45#include "MagickCore/image.h"
46#include "MagickCore/log.h"
47#include "MagickCore/monitor.h"
48#include "MagickCore/monitor-private.h"
49#include "MagickCore/pixel-accessor.h"
50
51/*
52 Static declarations.
53*/
54static 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*/
75MagickPrivate MagickBooleanType MonitorComponentGenesis(void)
76{
77 if (monitor_semaphore == (SemaphoreInfo *) NULL)
78 monitor_semaphore=AcquireSemaphoreInfo();
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*/
100MagickPrivate void MonitorComponentTerminus(void)
101{
102 if (monitor_semaphore == (SemaphoreInfo *) NULL)
103 ActivateSemaphoreInfo(&monitor_semaphore);
104 LockSemaphoreInfo(monitor_semaphore);
105 UnlockSemaphoreInfo(monitor_semaphore);
106 RelinquishSemaphoreInfo(&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%
125% The format of the SetImageProgress method is:
126%
127% MagickBooleanType SetImageProgress(const char *text,
128% const MagickOffsetType offset,const MagickSizeType extent)
129%
130% A description of each parameter follows:
131%
132% o image: the image.
133%
134% o text: description of the image processing operation.
135%
136% o offset: the offset relative to the extent parameter.
137%
138% o extent: the extent of the progress.
139%
140*/
141MagickExport MagickBooleanType SetImageProgress(const Image *image,
142 const char *tag,const MagickOffsetType offset,const MagickSizeType extent)
143{
144 char
145 message[MagickPathExtent];
146
147 MagickBooleanType
148 status;
149
150 if (image->progress_monitor == (MagickProgressMonitor) NULL)
151 return(MagickTrue);
152 (void) FormatLocaleString(message,MagickPathExtent,"%s/%s",
153 tag == (const char *) NULL ? "null" : tag,image->filename);
154 if (monitor_semaphore == (SemaphoreInfo *) NULL)
155 ActivateSemaphoreInfo(&monitor_semaphore);
156 LockSemaphoreInfo(monitor_semaphore);
157 status=image->progress_monitor(message,offset,extent,image->client_data);
158 (void) FormatLocaleString(message,MagickPathExtent,"%g%%:%s:%s",
159 (double) (100.0*offset*PerceptibleReciprocal(extent-1.0)),
160 tag == (const char *) NULL ? "null" : tag,image->filename);
161 (void) SetImageArtifact((Image *) image,"monitor:progress",message);
162 UnlockSemaphoreInfo(monitor_semaphore);
163 return(status);
164}
165
166/*
167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168% %
169% %
170% %
171% S e t I m a g e P r o g r e s s M o n i t o r %
172% %
173% %
174% %
175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176%
177% SetImageProgressMonitor() sets the image progress monitor to the specified
178% method and returns the previous progress monitor if any. The progress
179% monitor method looks like this:
180%
181% MagickBooleanType MagickProgressMonitor(const char *text,
182% const MagickOffsetType offset,const MagickSizeType extent,
183% void *client_data)
184%
185% If the progress monitor returns MagickFalse, the current operation is
186% interrupted.
187%
188% The format of the SetImageProgressMonitor method is:
189%
190% MagickProgressMonitor SetImageProgressMonitor(Image *image,
191% const MagickProgressMonitor progress_monitor,void *client_data)
192%
193% A description of each parameter follows:
194%
195% o image: the image.
196%
197% o progress_monitor: Specifies a pointer to a method to monitor progress of
198% an image operation.
199%
200% o client_data: Specifies a pointer to any client data.
201%
202*/
203MagickExport MagickProgressMonitor SetImageProgressMonitor(Image *image,
204 const MagickProgressMonitor progress_monitor,void *client_data)
205{
206 MagickProgressMonitor
207 previous_monitor;
208
209 previous_monitor=image->progress_monitor;
210 image->progress_monitor=progress_monitor;
211 image->client_data=client_data;
212 return(previous_monitor);
213}
214
215/*
216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217% %
218% %
219% %
220% 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 %
221% %
222% %
223% %
224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225%
226% SetImageInfoProgressMonitor() sets the image_info progress monitor to the
227% specified method and returns the previous progress monitor if any. The
228% progress monitor method looks like this:
229%
230% MagickBooleanType MagickProgressMonitor(const char *text,
231% const MagickOffsetType offset,const MagickSizeType extent,
232% void *client_data)
233%
234% If the progress monitor returns MagickFalse, the current operation is
235% interrupted.
236%
237% The format of the SetImageInfoProgressMonitor method is:
238%
239% MagickProgressMonitor SetImageInfoProgressMonitor(ImageInfo *image_info,
240% const MagickProgressMonitor progress_monitor,void *client_data)
241%
242% A description of each parameter follows:
243%
244% o image_info: the image info.
245%
246% o progress_monitor: Specifies a pointer to a method to monitor progress of
247% an image operation.
248%
249% o client_data: Specifies a pointer to any client data.
250%
251*/
252MagickExport MagickProgressMonitor SetImageInfoProgressMonitor(
253 ImageInfo *image_info,const MagickProgressMonitor progress_monitor,
254 void *client_data)
255{
256 MagickProgressMonitor
257 previous_monitor;
258
259 previous_monitor=image_info->progress_monitor;
260 image_info->progress_monitor=progress_monitor;
261 image_info->client_data=client_data;
262 return(previous_monitor);
263}