]> granicus.if.org Git - imagemagick/blob - www/magick-core.html
...
[imagemagick] / www / magick-core.html
1
2
3
4
5 <!DOCTYPE html>
6 <html lang="en">
7 <head>
8   <meta charset="utf-8" >
9   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" >
10   <title>MagickCore, Low-level C API @ ImageMagick</title>
11   <meta name="application-name" content="ImageMagick">
12   <meta name="description" content="ImageMagick® is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, JPEG-2000, GIF, WebP, Postscript, PDF, and SVG. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.">
13   <meta name="application-url" content="https://www.imagemagick.org">
14   <meta name="generator" content="PHP">
15   <meta name="keywords" content="magickcore, low-level, c, api, ImageMagick, PerlMagick, image processing, image, photo, software, Magick++, OpenMP, convert">
16   <meta name="rating" content="GENERAL">
17   <meta name="robots" content="INDEX, FOLLOW">
18   <meta name="generator" content="ImageMagick Studio LLC">
19   <meta name="author" content="ImageMagick Studio LLC">
20   <meta name="revisit-after" content="2 DAYS">
21   <meta name="resource-type" content="document">
22   <meta name="copyright" content="Copyright (c) 1999-2017 ImageMagick Studio LLC">
23   <meta name="distribution" content="Global">
24   <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1">
25   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
26   <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4">
27   <link href="../www/magick-core.html" rel="canonical">
28   <link href="../images/wand.png" rel="icon">
29   <link href="../images/wand.ico" rel="shortcut icon">
30   <link href="assets/magick.css" rel="stylesheet">
31 </head>
32 <body>
33   <header>
34   <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
35     <a class="navbar-brand" href="magick-core.html#">ImageMagick</a>
36     <button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
37     <span class="navbar-toggler-icon"></span>
38     </button>
39
40     <div class="navbar-collapse collapse" id="navbarsExampleDefault" style="">
41     <ul class="navbar-nav mr-auto">
42       <li class="nav-item ">
43         <a class="nav-link" href="../index.html">Home <span class="sr-only">(current)</span></a>
44       </li>
45       <li class="nav-item ">
46         <a class="nav-link" href="download.html">Download</a>
47       </li>
48       <li class="nav-item ">
49         <a class="nav-link" href="command-line-tools.html">Tools</a>
50       </li>
51       <li class="nav-item ">
52         <a class="nav-link" href="command-line-processing.html">Command-line</a>
53       </li>
54       <li class="nav-item ">
55         <a class="nav-link" href="resources.html">Resources</a>
56       </li>
57       <li class="nav-item ">
58         <a class="nav-link" href="develop.html">Develop</a>
59       </li>
60       <li class="nav-item">
61         <a class="nav-link" href="https://www.imagemagick.org/discourse-server/">Community</a>
62       </li>
63     </ul>
64     <form class="form-inline my-2 my-lg-0" action="https://www.imagemagick.org/script/search.php">
65       <!-- <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search"> -->
66       <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
67     </form>
68     </div>
69   </nav>
70   <div class="container">
71    <script async="async" src="http://localhost/pagead/js/adsbygoogle.js"></script>    <ins class="adsbygoogle"
72          style="display:block"
73          data-ad-client="ca-pub-3129977114552745"
74          data-ad-slot="6345125851"
75          data-ad-format="auto"></ins>
76     <script>
77       (adsbygoogle = window.adsbygoogle || []).push({});
78     </script>
79   </div>
80   </header>
81   <main role="main" class="container">
82     <div class="magick-template">
83 <div class="magick-header">
84
85 <p  class="lead magick-description">The <a href="api/MagickCore/index.html">MagickCore API</a> is a low-level interface between the C programming language and the ImageMagick image processing libraries and is recommended for wizard-level programmers only.  Unlike the <a href="magick-wand.html">MagickWand</a> C API which uses only a few opaque types and accessors, with MagickCore you almost exlusively access the structure members directly.  A description of the MagickCore public methods are found here:</p>
86
87 <ul>
88   <li><a href="api/magick.html">Initialize or Destroy the ImageMagick Environment</a></li>
89   <li><a href="api/constitute.html">Constitute an Image</a></li>
90   <li><a href="api/composite.html">Composite an Image</a></li>
91   <li><a href="api/image.html">Image Methods</a></li>
92   <li><a href="api/channel.html">Image Channel Methods</a></li>
93   <li><a href="api/color.html">Count the Colors in an Image</a></li>
94   <li><a href="api/colormap.html">Colormap Methods</a></li>
95   <li><a href="api/colorspace.html">Colorspace Methods</a></li>
96   <li><a href="api/distort.html">Image Distortions</a></li>
97   <li><a href="api/layer.html">Dealing with Image Layers</a></li>
98   <li><a href="api/profile.html">Dealing with Image Profiles</a></li>
99   <li><a href="api/quantize.html">Reduce the Number of Unique Colors in an Image</a></li>
100   <li><a href="api/histogram.html">Image Histograms</a></li>
101   <li><a href="api/segment.html">Segment an Image with Thresholding Fuzzy c-Means</a></li>
102   <li><a href="api/resize.html">Resize an Image</a></li>
103   <li><a href="api/transform.html">Transform an Image</a></li>
104   <li><a href="api/shear.html">Shear or Rotate an Image by an Arbitrary Angle</a></li>
105   <li><a href="api/enhance.html">Enhance an Image</a></li>
106   <li><a href="api/effect.html">Add an Effect</a></li>
107   <li><a href="api/morphology.html">Morphological Erosions, Dilations, Openings, and Closings</a></li>
108   <li><a href="api/fx.html">Add a Special Effect</a></li>
109   <li><a href="api/decorate.html">Decorate an Image</a></li>
110   <li><a href="api/attribute.html">Get/Set an Image Attribute</a></li>
111   <li><a href="api/property.html">Get/Set Image Properties</a></li>
112   <li><a href="api/statistic.html">Get Image Statistics</a></li>
113   <li><a href="api/feature.html">Get Image Features</a></li>
114   <li><a href="api/annotate.html">Annotate an Image</a></li>
115   <li><a href="api/paint.html">Paint on an Image</a></li>
116   <li><a href="api/draw.html">Draw on an Image</a></li>
117   <li><a href="api/montage.html">Create an Image Thumbnail</a></li>
118   <li><a href="api/fourier.html">Compute the discrete Fourier transform (DFT)</a></li>
119   <li><a href="api/compare.html">Compare an Image to a Reconstructed Image</a></li>
120   <li><a href="api/display.html">Interactively Display and Edit an Image</a></li>
121   <li><a href="api/animate.html">Interactively Animate an Image Sequence</a></li>
122   <li><a href="api/cipher.html">Convert to and from Cipher Pixels</a></li>
123   <li><a href="api/list.html">Working with Image Lists</a></li>
124   <li><a href="api/image-view.html">Image View Methods</a></li>
125   <li><a href="api/cache.html">Get or Set Image Pixels</a></li>
126   <li><a href="api/cache-view.html">Working with Cache Views</a></li>
127   <li><a href="api/stream.html">The Pixel FIFO</a></li>
128   <li><a href="api/blob.html">Read or Write Binary Large OBjects</a></li>
129   <li><a href="api/module.html">Loadable Modules</a></li>
130   <li><a href="api/signature.html">Compute a Message Digest for an Image</a></li>
131   <li><a href="api/registry.html">The Image Registry</a></li>
132   <li><a href="api/exception.html">Dealing with Exceptions</a></li>
133   <li><a href="api/memory.html">Memory Allocation</a></li>
134   <li><a href="api/resource.html">Monitor or Limit Resource Consumption</a></li>
135   <li><a href="api/monitor.html">Monitor the Progress of an Image Operation</a></li>
136   <li><a href="api/version.html">Get the Version and Copyrights</a></li>
137   <li><a href="api/mime.html">Mime Methods</a></li>
138   <li><a href="api/deprecate.html">Deprecated Methods</a></li>
139   <li><a href="../www/exception.html">Error and Warning Codes</a></li>
140 </ul>
141
142 <p>After you write your MagickCore program, compile it like this:</p>
143
144 <pre class="highlight"><code>cc -o core core.c `pkg-config --cflags --libs MagickWand`
145 </code></pre>
146
147 <p>Set the <code>PKG_CONFIG_PATH</code> environment variable if ImageMagick is not in your default system path:</p>
148
149 <pre class="highlight"><code>export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
150 </code></pre>
151
152 <p>Here is a example program that utilizes the MagickCore API to get you started, <a href="https://www.imagemagick.org/source/core.c">core.c</a>. It reads a GIF image, creates a thumbnail, and writes it to disk in the PNG image format.</p>
153
154 <pre class="pre-scrollable"><code>#include &lt;stdio.h>
155 #include &lt;stdlib.h>
156 #include &lt;string.h>
157 #include &lt;time.h>
158 #include &lt;MagickCore/MagickCore.h>
159
160 int main(int argc,char **argv)
161 {
162   ExceptionInfo
163     *exception;
164
165   Image
166     *image,
167     *images,
168     *resize_image,
169     *thumbnails;
170
171   ImageInfo
172     *image_info;
173
174   if (argc != 3)
175     {
176       (void) fprintf(stdout,"Usage: %s image thumbnail\n",argv[0]);
177       exit(0);
178     }
179   /*
180     Initialize the image info structure and read an image.
181   */
182   MagickCoreGenesis(*argv,MagickTrue);
183   exception=AcquireExceptionInfo();
184   image_info=CloneImageInfo((ImageInfo *) NULL);
185   (void) strcpy(image_info-&gt;filename,argv[1]);
186   images=ReadImage(image_info,exception);
187   if (exception-&gt;severity != UndefinedException)
188     CatchException(exception);
189   if (images == (Image *) NULL)
190     exit(1);
191   /*
192     Convert the image to a thumbnail.
193   */
194   thumbnails=NewImageList();
195   while ((image=RemoveFirstImageFromList(&amp;images)) != (Image *) NULL)
196   {
197     resize_image=ResizeImage(image,106,80,LanczosFilter,exception);
198     if (resize_image == (Image *) NULL)
199       MagickError(exception-&gt;severity,exception-&gt;reason,exception-&gt;description);
200     (void) AppendImageToList(&amp;thumbnails,resize_image);
201     DestroyImage(image);
202   }
203   /*
204     Write the image thumbnail.
205   */
206   (void) strcpy(thumbnails-&gt;filename,argv[2]);
207   WriteImage(image_info,thumbnails,exception);
208   /*
209     Destroy the image thumbnail and exit.
210   */
211   thumbnails=DestroyImageList(thumbnails);
212   image_info=DestroyImageInfo(image_info);
213   exception=DestroyExceptionInfo(exception);
214   MagickCoreTerminus();
215   return(0);
216 }</code></pre>
217 <p><a id="image-view"></a>Now lets perform the same contrast enhancement while taking advantage of our dual or quad-core processing system by running the algorithm in parallel utilizing wand views.  The <a href="https://www.imagemagick.org/source/core/sigmoidal-contrast.c">sigmoidal-contrast.c</a> module reads an image, applies sigmoidal non-linearity contrast control, and writes the result to disk just like the previous contrast enhancement program, but now it does its work in parallel (assumes ImageMagick is built with OpenMP support).</p>
218
219 <pre class="pre-scrollable"><code>#include &lt;stdio.h>
220 #include &lt;stdlib.h>
221 #include &lt;math.h>
222 #include &lt;MagickCore/MagickCore.h>
223
224 static MagickBooleanType SigmoidalContrast(ImageView *contrast_view,
225   const ssize_t y,const int id,void *context)
226 {
227 #define QuantumScale  ((MagickRealType) 1.0/(MagickRealType) QuantumRange)
228 #define SigmoidalContrast(x) \
229   (QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503)
230
231   RectangleInfo
232     extent;
233
234   register IndexPacket
235     *indexes;
236
237   register PixelPacket
238     *pixels;
239
240   register ssize_t
241     x;
242
243   extent=GetImageViewExtent(contrast_view);
244   pixels=GetImageViewAuthenticPixels(contrast_view);
245   for (x=0; x &lt; (ssize_t) (extent.width-extent.x); x++)
246   {
247     SetPixelRed(pixels,RoundToQuantum(SigmoidalContrast(GetPixelRed(pixels)));
248     SetPixelGreen(pixels,RoundToQuantum(SigmoidalContrast(GetPixelGreen(pixels)));
249     SetPixelBlue(pixels,RoundToQuantum(SigmoidalContrast(GetPixelBlue(pixels)));
250     SetPixelOpacity(pixels,RoundToQuantum(SigmoidalContrast(GetPixelOpacity(pixels)));
251     pixels++;
252   }
253   indexes=GetImageViewAuthenticIndexes(contrast_view);
254   if (indexes != (IndexPacket *) NULL)
255     for (x=0; x &lt; (ssize_t) (extent.width-extent.x); x++)
256       SetPixelIndex(indexes+x,RoundToQuantum(SigmoidalContrast(GetPixelIndex(indexes+x))));
257   return(MagickTrue);
258 }
259
260 int main(int argc,char **argv)
261 {
262 #define ThrowImageException(image) \
263 { \
264  \
265   CatchException(exception); \
266   if (contrast_image != (Image *) NULL) \
267     contrast_image=DestroyImage(contrast_image); \
268   exit(-1); \
269 }
270 #define ThrowViewException(view) \
271 { \
272   char \
273     *description; \
274  \
275   ExceptionType \
276     severity; \
277  \
278   description=GetImageViewException(view,&amp;severity); \
279   (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
280   description=DestroyString(description); \
281   exit(-1); \
282 }
283
284   ExceptionInfo
285     *exception;
286
287   Image
288     *contrast_image;
289
290   ImageInfo
291     *image_info;
292
293   ImageView
294     *contrast_view;
295
296   MagickBooleanType
297     status;
298
299   if (argc != 3)
300     {
301       (void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]);
302       exit(0);
303     }
304   /*
305     Read an image.
306   */
307   MagickCoreGenesis(*argv,MagickTrue);
308   image_info=AcquireImageInfo();
309   (void) CopyMagickString(image_info->filename,argv[1],MaxTextExtent);
310   exception=AcquireExceptionInfo();
311   contrast_image=ReadImage(image_info,exception);
312   if (contrast_image == (Image *) NULL)
313     ThrowImageException(contrast_image);
314   /*
315     Sigmoidal non-linearity contrast control.
316   */
317   contrast_view=NewImageView(contrast_image);
318   if (contrast_view == (ImageView *) NULL)
319     ThrowImageException(contrast_image);
320   status=UpdateImageViewIterator(contrast_view,SigmoidalContrast,(void *) NULL);
321   if (status == MagickFalse)
322     ThrowImageException(contrast_image);
323   contrast_view=DestroyImageView(contrast_view);
324   /*
325     Write the image then destroy it.
326   */
327   status=WriteImages(image_info,contrast_image,argv[2],exception);
328   if (status == MagickFalse)
329     ThrowImageException(contrast_image);
330   contrast_image=DestroyImage(contrast_image);
331   exception=DestroyExceptionInfo(exception);
332   image_info=DestroyImageInfo(image_info);
333   MagickCoreTerminus();
334   return(0);
335 }</code></pre>
336 </div>
337     </div>
338   </main><!-- /.container -->
339   <footer class="magick-footer">
340     <p><a href="security-policy.html">Security</a> •
341     <a href="architecture.html">Architecture</a> •
342     <a href="links.html">Related</a> •
343      <a href="sitemap.html">Sitemap</a> •
344     <a href="http://pgp.mit.edu/pks/lookup?op=get&amp;search=0x89AB63D48277377A">Public Key</a>
345 </p>
346     <p><a href="support.html">Donate</a> •
347     <a href="magick-core.html#">Back to top</a> •
348     <a href="https://www.imagemagick.org/script/contact.php">Contact Us</a></p>
349         <p><small>© 1999-2018 ImageMagick Studio LLC</small></p>
350   </footer>
351
352   <!-- Javascript assets -->
353   <script src="assets/magick.js" crossorigin="anonymous"></script>
354   <script>window.jQuery || document.write('<script src="assets/jquery.min.js"><\/script>')</script>
355 </body>
356 </html>
357 <!-- Magick Cache 9th December 2017 17:38 -->