1 2 3 4 5 <!DOCTYPE html> 6 <html lang="en"> 7 <head> 8 <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" /> 9 <title>ImageMagick: MagickCore, Low-level C API for ImageMagick</title> 10 <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 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 Bzier curves."/> 13 <meta name="application-url" content="http://www.imagemagick.org"/> 14 <meta name="generator" content="PHP"/> 15 <meta name="keywords" content="magickcore, low-level, c, api, for, imagemagick, 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-2015 ImageMagick Studio LLC"/> 23 <meta name="distribution" content="Global"/> 24 <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1"/> 25 <link rel="icon" href="../image/wand.png"/> 26 <link rel="shortcut icon" href="../image/wand.ico"/> 27 <link rel="stylesheet" href="../css/magick.php"/> 28 </head> 29 <body> 30 <div class="main"> 31 <div class="magick-masthead"> 32 <div class="container"> 33 <script async="async" src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" 34 style="display:block" 35 data-ad-client="ca-pub-3129977114552745" 36 data-ad-slot="6345125851" 37 data-ad-format="auto"></ins> 38 <script> 39 (adsbygoogle = window.adsbygoogle || []).push({}); 40 </script> 41 <nav class="magick-nav"> 42 <a class="magick-nav-item " href="../index.php">Home</a> 43 <a class="magick-nav-item " href="binary-releases.php">Download</a> 44 <a class="magick-nav-item " href="command-line-tools.php">Tools</a> 45 <a class="magick-nav-item " href="command-line-processing.php">Command-line</a> 46 <a class="magick-nav-item " href="resources.php">Resources</a> 47 <a class="magick-nav-item " href="api.php">Develop</a> 48 <a class="magick-nav-item " href="search.php">Search</a> 49 <a class="magick-nav-item pull-right" href="http://www.imagemagick.org/discourse-server/">Community</a> 50 </nav> 51 </div> 52 </div> 53 <div class="container"> 54 <div class="magick-header"> 55 56 <p class="lead magick-description">The <a href="http://nextgen.imagemagick.org/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.php">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> 57 58 <ul> 59 <li><a href="../api/magick.php">Initialize or Destroy the ImageMagick Environment</a></li> 60 <li><a href="../api/constitute.php">Constitute an Image</a></li> 61 <li><a href="../api/composite.php">Composite an Image</a></li> 62 <li><a href="../api/image.php">Image Methods</a></li> 63 <li><a href="../api/channel.php">Image Channel Methods</a></li> 64 <li><a href="../api/color.php">Count the Colors in an Image</a></li> 65 <li><a href="../api/colormap.php">Colormap Methods</a></li> 66 <li><a href="../api/colorspace.php">Colorspace Methods</a></li> 67 <li><a href="../api/distort.php">Image Distortions</a></li> 68 <li><a href="../api/layer.php">Dealing with Image Layers</a></li> 69 <li><a href="../api/profile.php">Dealing with Image Profiles</a></li> 70 <li><a href="../api/quantize.php">Reduce the Number of Unique Colors in an Image</a></li> 71 <li><a href="../api/histogram.php">Image Histograms</a></li> 72 <li><a href="../api/segment.php">Segment an Image with Thresholding Fuzzy c-Means</a></li> 73 <li><a href="../api/resize.php">Resize an Image</a></li> 74 <li><a href="../api/transform.php">Transform an Image</a></li> 75 <li><a href="../api/shear.php">Shear or Rotate an Image by an Arbitrary Angle</a></li> 76 <li><a href="../api/enhance.php">Enhance an Image</a></li> 77 <li><a href="../api/effect.php">Add an Effect</a></li> 78 <li><a href="../api/morphology.php">Morphological Erosions, Dilations, Openings, and Closings</a></li> 79 <li><a href="../api/fx.php">Add a Special Effect</a></li> 80 <li><a href="../api/decorate.php">Decorate an Image</a></li> 81 <li><a href="../api/attribute.php">Get/Set an Image Attribute</a></li> 82 <li><a href="../api/property.php">Get/Set Image Properties</a></li> 83 <li><a href="../api/statistic.php">Get Image Statistics</a></li> 84 <li><a href="../api/feature.php">Get Image Features</a></li> 85 <li><a href="../api/annotate.php">Annotate an Image</a></li> 86 <li><a href="../api/paint.php">Paint on an Image</a></li> 87 <li><a href="../api/draw.php">Draw on an Image</a></li> 88 <li><a href="../api/montage.php">Create an Image Thumbnail</a></li> 89 <li><a href="../api/fourier.php">Compute the discrete Fourier transform (DFT)</a></li> 90 <li><a href="../api/compare.php">Compare an Image to a Reconstructed Image</a></li> 91 <li><a href="../api/display.php">Interactively Display and Edit an Image</a></li> 92 <li><a href="../api/animate.php">Interactively Animate an Image Sequence</a></li> 93 <li><a href="../api/cipher.php">Convert to and from Cipher Pixels</a></li> 94 <li><a href="../api/list.php">Working with Image Lists</a></li> 95 <li><a href="../api/image-view.php">Image View Methods</a></li> 96 <li><a href="../api/cache.php">Get or Set Image Pixels</a></li> 97 <li><a href="../api/cache-view.php">Working with Cache Views</a></li> 98 <li><a href="../api/stream.php">The Pixel FIFO</a></li> 99 <li><a href="../api/blob.php">Read or Write Binary Large OBjects</a></li> 100 <li><a href="../api/module.php">Loadable Modules</a></li> 101 <li><a href="../api/signature.php">Compute a Message Digest for an Image</a></li> 102 <li><a href="../api/registry.php">The Image Registry</a></li> 103 <li><a href="../api/exception.php">Dealing with Exceptions</a></li> 104 <li><a href="../api/memory.php">Memory Allocation</a></li> 105 <li><a href="../api/resource.php">Monitor or Limit Resource Consumption</a></li> 106 <li><a href="../api/monitor.php">Monitor the Progress of an Image Operation</a></li> 107 <li><a href="../api/version.php">Get the Version and Copyrights</a></li> 108 <li><a href="../api/mime.php">Mime Methods</a></li> 109 <li><a href="../api/deprecate.php">Deprecated Methods</a></li> 110 <li><a href="exception.php">Error and Warning Codes</a></li> 111 </ul> 112 113 <p>After you write your MagickCore program, compile it like this:</p> 114 115 <pre> 116 cc -o core core.c `pkg-config --cflags --libs MagickCore` 117 </pre> 118 119 <p>Note, if your instance of ImageMagick does not support modules but does include support for the WMF image format, you'll need to link with the <a href="magick-wand.php">MagickWand</a> library instead (since it is a dependency of the WMF image format):</p> 120 121 <pre> 122 cc -o core core.c `pkg-config --cflags --libs MagickWand` 123 </pre> 124 125 <p>Set the <code>PKG_CONFIG_PATH</code> environment variable if ImageMagick is not in your default system path:</p> 126 127 <pre> 128 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig 129 </pre> 130 131 <p>Here is a example program that utilizes the MagickCore API to get you started, <a href="../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> 132 133 <pre class="pre-scrollable">#include <stdio.h> 134 #include <stdlib.h> 135 #include <string.h> 136 #include <time.h> 137 #include <magick/MagickCore.h> 138 139 int main(int argc,char **argv) 140 { 141 ExceptionInfo 142 *exception; 143 144 Image 145 *image, 146 *images, 147 *resize_image, 148 *thumbnails; 149 150 ImageInfo 151 *image_info; 152 153 if (argc != 3) 154 { 155 (void) fprintf(stdout,"Usage: %s image thumbnail\n",argv[0]); 156 exit(0); 157 } 158 /* 159 Initialize the image info structure and read an image. 160 */ 161 MagickCoreGenesis(*argv,MagickTrue); 162 exception=AcquireExceptionInfo(); 163 image_info=CloneImageInfo((ImageInfo *) NULL); 164 (void) strcpy(image_info->filename,argv[1]); 165 images=ReadImage(image_info,exception); 166 if (exception->severity != UndefinedException) 167 CatchException(exception); 168 if (images == (Image *) NULL) 169 exit(1); 170 /* 171 Convert the image to a thumbnail. 172 */ 173 thumbnails=NewImageList(); 174 while ((image=RemoveFirstImageFromList(&images)) != (Image *) NULL) 175 { 176 resize_image=ResizeImage(image,106,80,LanczosFilter,1.0,exception); 177 if (resize_image == (Image *) NULL) 178 MagickError(exception->severity,exception->reason,exception->description); 179 (void) AppendImageToList(&thumbnails,resize_image); 180 DestroyImage(image); 181 } 182 /* 183 Write the image thumbnail. 184 */ 185 (void) strcpy(thumbnails->filename,argv[2]); 186 WriteImage(image_info,thumbnails); 187 /* 188 Destroy the image thumbnail and exit. 189 */ 190 thumbnails=DestroyImageList(thumbnails); 191 image_info=DestroyImageInfo(image_info); 192 exception=DestroyExceptionInfo(exception); 193 MagickCoreTerminus(); 194 return(0); 195 }</pre> 196 <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="../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> 197 198 <pre class="pre-scrollable">#include <stdio.h> 199 #include <stdlib.h> 200 #include <math.h> 201 #include <magick/MagickCore.h> 202 203 static MagickBooleanType SigmoidalContrast(ImageView *contrast_view, 204 const ssize_t y,const int id,void *context) 205 { 206 #define QuantumScale ((MagickRealType) 1.0/(MagickRealType) QuantumRange) 207 #define SigmoidalContrast(x) \ 208 (QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503) 209 210 RectangleInfo 211 extent; 212 213 register IndexPacket 214 *indexes; 215 216 register PixelPacket 217 *pixels; 218 219 register ssize_t 220 x; 221 222 extent=GetImageViewExtent(contrast_view); 223 pixels=GetImageViewAuthenticPixels(contrast_view); 224 for (x=0; x < (ssize_t) (extent.width-extent.x); x++) 225 { 226 SetPixelRed(pixels,RoundToQuantum(SigmoidalContrast(GetPixelRed(pixels))); 227 SetPixelGreen(pixels,RoundToQuantum(SigmoidalContrast(GetPixelGreen(pixels))); 228 SetPixelBlue(pixels,RoundToQuantum(SigmoidalContrast(GetPixelBlue(pixels))); 229 SetPixelOpacity(pixels,RoundToQuantum(SigmoidalContrast(GetPixelOpacity(pixels))); 230 pixels++; 231 } 232 indexes=GetImageViewAuthenticIndexes(contrast_view); 233 if (indexes != (IndexPacket *) NULL) 234 for (x=0; x < (ssize_t) (extent.width-extent.x); x++) 235 SetPixelIndex(indexes+x,RoundToQuantum(SigmoidalContrast(GetPixelIndex(indexes+x)))); 236 return(MagickTrue); 237 } 238 239 int main(int argc,char **argv) 240 { 241 #define ThrowImageException(image) \ 242 { \ 243 \ 244 CatchException(exception); \ 245 if (contrast_image != (Image *) NULL) \ 246 contrast_image=DestroyImage(contrast_image); \ 247 exit(-1); \ 248 } 249 #define ThrowViewException(view) \ 250 { \ 251 char \ 252 *description; \ 253 \ 254 ExceptionType \ 255 severity; \ 256 \ 257 description=GetImageViewException(view,&severity); \ 258 (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \ 259 description=DestroyString(description); \ 260 exit(-1); \ 261 } 262 263 ExceptionInfo 264 *exception; 265 266 Image 267 *contrast_image; 268 269 ImageInfo 270 *image_info; 271 272 ImageView 273 *contrast_view; 274 275 MagickBooleanType 276 status; 277 278 if (argc != 3) 279 { 280 (void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]); 281 exit(0); 282 } 283 /* 284 Read an image. 285 */ 286 MagickCoreGenesis(*argv,MagickTrue); 287 image_info=AcquireImageInfo(); 288 (void) CopyMagickString(image_info->filename,argv[1],MaxTextExtent); 289 exception=AcquireExceptionInfo(); 290 contrast_image=ReadImage(image_info,exception); 291 if (contrast_image == (Image *) NULL) 292 ThrowImageException(contrast_image); 293 /* 294 Sigmoidal non-linearity contrast control. 295 */ 296 contrast_view=NewImageView(contrast_image); 297 if (contrast_view == (ImageView *) NULL) 298 ThrowImageException(contrast_image); 299 status=UpdateImageViewIterator(contrast_view,SigmoidalContrast,(void *) NULL); 300 if (status == MagickFalse) 301 ThrowImageException(contrast_image); 302 contrast_view=DestroyImageView(contrast_view); 303 /* 304 Write the image then destroy it. 305 */ 306 status=WriteImages(image_info,contrast_image,argv[2],exception); 307 if (status == MagickFalse) 308 ThrowImageException(contrast_image); 309 contrast_image=DestroyImage(contrast_image); 310 exception=DestroyExceptionInfo(exception); 311 image_info=DestroyImageInfo(image_info); 312 MagickCoreTerminus(); 313 return(0); 314 }</pre> 315 </div> 316 <footer class="magick-footer"> 317 <p><a href="support.php">Donate</a> 318 <a href="sitemap.php">Sitemap</a> 319 <a href="links.php">Related</a> 320 <a href="architecture.php">Architecture</a> 321 </p> 322 <p><a href="magick-core.php#">Back to top</a> 323 <a href="http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> 324 <a href="contact.php">Contact Us</a></p> 325 <p><small> 1999-2016 ImageMagick Studio LLC</small></p> 326 </footer> 327 </div><!-- /.container --> 328 329 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 330 <script src="http://nextgen.imagemagick.org/js/magick.php"></script> 331 </div> 332 </body> 333 </html> 334