| 1 |
|
| 2 |
|
| 3 |
<!DOCTYPE html> |
| 4 |
<html lang="en" data-bs-theme="dark"> |
| 5 |
|
| 6 |
|
| 7 |
<head> |
| •8 |
<meta charset="utf-8" /> |
| 9 |
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" /> |
| 10 |
<title>ImageMagick | MagickWand, C API</title> |
| •11 |
<meta name="description" content="Recommended interface between the C programming language and the ImageMagick image processing libraries." /> |
| 12 |
<link rel="canonical" href="index.html" /> |
| 13 |
<meta name="robots" content="index, follow" /> |
| 14 |
<meta name="theme-color" content="#000000" /> |
| 15 |
<meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" /> |
| •16 |
<link rel="shortcut icon" href="../image/wand.png" type="image/png" /> |
| 17 |
<link rel="apple-touch-icon" href="../image/wand.png" type="image/png" /> |
| 18 |
<link rel="preconnect" href="https://localhost/" /> |
| 19 |
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" as="style" crossorigin="anonymous" /> |
| 20 |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" crossorigin="anonymous" /> |
| 21 |
|
| 22 |
<style> |
| 23 |
html { |
| 24 |
scroll-padding-top: 70px; |
| 25 |
} |
| 26 |
|
| 27 |
a.nav-link:hover, |
| 28 |
a.dropdown-item:hover { |
| 29 |
color: #ffc107 !important; |
| 30 |
text-shadow: 0px 2px 4px rgba(255, 193, 7, 0.8); |
| 31 |
} |
| 32 |
|
| 33 |
.btn-outline-warning { |
| 34 |
color: #cd7f32; |
| 35 |
border-color: #cd7f32; |
| 36 |
} |
| 37 |
|
| 38 |
.navbar-brand { |
| 39 |
color: #d4af37; |
| 40 |
transition: color 0.3s ease, text-shadow 0.3s ease; |
| 41 |
} |
| 42 |
|
| 43 |
.navbar-brand:hover { |
| 44 |
color: #e9c03d; |
| 45 |
text-shadow: 0px 2px 4px rgba(203, 163, 120, 0.6); |
| 46 |
} |
| 47 |
|
| 48 |
:root { |
| 49 |
--bs-code-color: revert; |
| 50 |
} |
| 51 |
</style> |
| 52 |
|
| •53 |
<meta property="og:title" content="ImageMagick | MagickWand, C API" /> |
| 54 |
<meta property="og:description" content="Recommended interface between the C programming language and the ImageMagick image processing libraries." /> |
| •55 |
<meta property="og:image" content="https://imagemagick.org/image/logo.png" /> |
| 56 |
<meta property="og:logo" content="https://imagemagick.org/image/logo.png" /> |
| 57 |
<meta property="og:url" content="https://imagemagick.org/magick-wand/" /> |
| •58 |
<meta property="og:type" content="website" /> |
| 59 |
<meta property="og:site_name" content="ImageMagick" /> |
| 60 |
<meta property="og:locale" content="en_us" /> |
| 61 |
|
| •62 |
<meta name="twitter:card" content="summary_large_image" /> |
| 63 |
$site=strtolower("ImageMagick"); |
| •64 |
<meta name="twitter:site" content="@imagemagick" /> |
| 65 |
<meta name="twitter:creator" content="@imagemagick" /> |
| 66 |
<meta name="twitter:title" content="ImageMagick | MagickWand, C API" /> |
| •67 |
<meta name="twitter:description" content="$this- />description" /> |
| 68 |
<meta name="twitter:image" content="https://imagemagick.org/image/logo.png" /> |
| •69 |
<meta name="twitter:image:alt" content="ImageMagick logo and tag line" /> |
| 70 |
|
| 71 |
<script type="application/ld+json"> |
| 72 |
{ |
| 73 |
"@context": "https://schema.org", |
| 74 |
"@type": "SoftwareApplication", |
| 75 |
"name": "ImageMagick", |
| 76 |
"url": "ImageMagick | MagickWand, C API", |
| 77 |
"image": "https://imagemagick.org/image/logo.png", |
| 78 |
"description": "$this->description", |
| 79 |
"applicationCategory": "Multimedia", |
| 80 |
"operatingSystem": "Windows, macOS, Linux, Unix", |
| 81 |
"softwareVersion": "7.1.2-27", |
| 82 |
"license": "https://imagemagick.org/license/", |
| 83 |
"creator": { |
| 84 |
"@type": "Organization", |
| 85 |
"name": "ImageMagick Studio LLC", |
| 86 |
"url": "https://imagemagick.org" |
| 87 |
}, |
| 88 |
"keywords": [ |
| 89 |
"".ucfirst($title)."", |
| 90 |
"image processing software", |
| 91 |
"image conversion tool", |
| 92 |
"batch image editing", |
| 93 |
"open-source image editor", |
| 94 |
"ImageMagick command-line", |
| 95 |
"resize images ImageMagick", |
| 96 |
"crop and rotate images", |
| 97 |
"ImageMagick tutorial", |
| 98 |
"ImageMagick automation", |
| 99 |
"ImageMagick for developers", |
| 100 |
"ImageMagick CLI", |
| 101 |
"ImageMagick filters and effects", |
| 102 |
"ImageMagick scripting", |
| 103 |
"ImageMagick API integration" |
| 104 |
], |
| 105 |
"sameAs": [ |
| 106 |
"https://github.com/ImageMagick", |
| 107 |
"https://x.com/imagemagick" |
| 108 |
], |
| 109 |
"offers": { |
| 110 |
"@type": "Offer", |
| 111 |
"price": "0.00", |
| 112 |
"priceCurrency": "USD" |
| 113 |
} |
| 114 |
} |
| 115 |
</script> |
| 116 |
|
| •117 |
<script async="true" src="https://localhost/cse.js?cx=8720b81722164487b"></script> |
| 118 |
<script async="true" src="https://localhost/pagead/js/adsbygoogle.js?client=ca-pub-3129977114552745" crossorigin="anonymous"></script> |
| 119 |
</head> |
| 120 |
|
| 121 |
<body> |
| 122 |
<script> |
| 123 |
function setTheme(theme) { |
| 124 |
localStorage.setItem('theme', theme); |
| 125 |
updateThemeIcon(theme); |
| 126 |
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? getSystemTheme() : theme); |
| 127 |
} |
| 128 |
function getSystemTheme() { |
| 129 |
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; |
| 130 |
} |
| 131 |
function updateThemeIcon(theme) { |
| 132 |
const iconMap = { |
| 133 |
light: '☀️', |
| 134 |
dark: '🌙', |
| 135 |
auto: '🌓' |
| 136 |
}; |
| 137 |
document.getElementById('currentThemeIcon').textContent = iconMap[theme] || '🌓'; |
| 138 |
} |
| 139 |
document.addEventListener('DOMContentLoaded', () => { |
| 140 |
const savedTheme = localStorage.getItem('theme') || 'auto'; |
| 141 |
setTheme(savedTheme); |
| 142 |
}); |
| 143 |
</script> |
| 144 |
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top"> |
| 145 |
<div class="container-fluid"> |
| 146 |
<a class="navbar-brand fw-bold" href="../index-2.html" title="ImageMagick">ImageMagick</a> |
| 147 |
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#magick-navbars" aria-controls="magick-navbars" aria-expanded="false" aria-label="Toggle navigation"> |
| 148 |
<span class="navbar-toggler-icon"></span> |
| 149 |
</button> |
| 150 |
|
| 151 |
<div class="collapse navbar-collapse" id="magick-navbars"> |
| 152 |
<ul class="navbar-nav me-auto"> |
| 153 |
<li class="nav-item"> |
| •154 |
<a class="nav-link" href="../download/index.html">Download</a> |
| 155 |
</li> |
| 156 |
<li class="nav-item"> |
| •157 |
<a class="nav-link" href="../command-line-tools/index.html">Tools</a> |
| 158 |
</li> |
| 159 |
<li class="nav-item"> |
| •160 |
<a class="nav-link" href="../command-line-processing/index.html">CLI</a> |
| 161 |
</li> |
| 162 |
<li class="nav-item"> |
| •163 |
<a class="nav-link" href="../develop/index.html">Develop</a> |
| 164 |
</li> |
| 165 |
<li class="nav-item"> |
| 166 |
<a class="nav-link" rel="noopener noreferrer" target="_blank" href="https://github.com/ImageMagick/ImageMagick/discussions">Community</a> |
| 167 |
</li> |
| 168 |
</ul> |
| 169 |
<ul class="navbar-nav ms-auto"> |
| 170 |
<li class="nav-item ms-3"> |
| 171 |
<form class="d-flex form-inline" action="https://imagemagick.org/magick-wand/"> |
| •172 |
<input class="form-control me-2" type="text" name="q" placeholder="Search site..." aria-label="Search" /> |
| 173 |
<button class="btn btn-outline-warning" type="submit" name="sa">Search</button> |
| 174 |
</form> |
| 175 |
</li> |
| 176 |
<li class="nav-item dropdown ms-3"> |
| 177 |
<a class="nav-link dropdown-toggle" href="#" id="themeDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> |
| 178 |
<span id="currentThemeIcon">🌓</span> |
| 179 |
</a> |
| 180 |
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="themeDropdown"> |
| 181 |
<li><a class="dropdown-item" href="#" onclick="setTheme('light')">☀️ Light</a></li> |
| 182 |
<li><a class="dropdown-item" href="#" onclick="setTheme('dark')">🌙 Dark</a></li> |
| 183 |
<li><a class="dropdown-item" href="#" onclick="setTheme('auto')">🌓 Auto</a></li> |
| 184 |
</ul> |
| 185 |
</li> |
| 186 |
</ul> |
| 187 |
</div> |
| 188 |
</div> |
| 189 |
</nav> |
| 190 |
|
| 191 |
<div class="col-lg-8 mx-auto text-body-secondary pt-5 pt-lg-5"> |
| 192 |
<header class="d-flex align-items-center pb-3 mb-5 border-bottom"> |
| 193 |
<div class="mt-3 ms-3"> |
| 194 |
<a href="../index-2.html" class="text-decoration-none"> |
| 195 |
<h1 class="fs-2 mb-1 display-5">MagickWand, C API</h1> |
| 196 |
</a> |
| 197 |
<h2 class="fs-5 text-muted h4">ImageMagick</h2> |
| 198 |
</div> |
| 199 |
</header> |
| 200 |
|
| 201 |
<main role="main" class="container"> |
| 202 |
<div class="row g-5"> |
| 203 |
<div class="col-md-9"> |
| 204 |
<div> |
| 205 |
<p class="lead">The <a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand">MagickWand API</a> is the recommended interface between the C programming language and the ImageMagick image processing libraries. Unlike the <a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickCore">MagickCore</a> C API, MagickWand uses only a few opaque types. Accessors are available to set or get important wand properties. A description of the MagickWand public methods are found on GitHub:</p> |
| 206 |
|
| 207 |
<ul> |
| 208 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/MagickWand.h">Magick Wand Methods</a></li> |
| 209 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/magick-property.h">Set or Get Magick Wand Properties</a></li> |
| 210 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/magick-image.h">Magick Wand Image Methods</a></li> |
| 211 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/pixel-iterator.h">Pixel Iterator Methods</a></li> |
| 212 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/pixel-wand.h">Pixel Wand Methods</a></li> |
| 213 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/drawing-wand.h">Image Vector Drawing</a></li> |
| 214 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/mogrify.h">Command-line Interface</a></li> |
| 215 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/wand-view.h">Wand View Methods</a></li> |
| 216 |
<li><a href="https://github.com/ImageMagick/ImageMagick/tree/main/MagickWand/deprecate.h">Deprecated Methods</a></li> |
| 217 |
<li><a href="https://imagemagick.org/exception/">Error and Warning Codes</a></li> |
| 218 |
</ul> |
| 219 |
|
| 220 |
<p>After you write your MagickWand program, compile it like this:</p> |
| 221 |
|
| 222 |
<pre class="p-3 mb-2 text-body-secondary bg-body-tertiary"><samp>$ cc `MagickWand-config --cflags --cppflags` -O2 -o wand wand.c `MagickWand-config --ldflags --libs`</samp></pre> |
| 223 |
|
| 224 |
<p>Set the <code>PKG_CONFIG_PATH</code> environment variable if ImageMagick is not in your default system path:</p> |
| 225 |
|
| 226 |
<pre class="p-3 mb-2 text-body-secondary bg-body-tertiary"><samp>$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig</samp></pre> |
| 227 |
|
| 228 |
<p>Here is a example program that utilizes the MagickWand API to get you started, <a href="https://imagemagick.org/source/wand.c">wand.c</a>. It reads an image, creates a thumbnail, and writes the result to disk.</p> |
| 229 |
|
| 230 |
<pre class="overflow-auto p-3 mb-2 text-body-secondary bg-body-tertiary" style="max-height:75svh;"><code>#include <stdio.h> |
| 231 |
#include <stdlib.h> |
| 232 |
#include <MagickWand/MagickWand.h> |
| 233 |
|
| 234 |
int main(int argc,char **argv) |
| 235 |
{ |
| 236 |
#define ThrowWandException(wand) \ |
| 237 |
{ \ |
| 238 |
char \ |
| 239 |
*description; \ |
| 240 |
\ |
| 241 |
ExceptionType \ |
| 242 |
severity; \ |
| 243 |
\ |
| 244 |
description=MagickGetException(wand,&severity); \ |
| 245 |
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \ |
| 246 |
description=(char *) MagickRelinquishMemory(description); \ |
| 247 |
exit(-1); \ |
| 248 |
} |
| 249 |
|
| 250 |
MagickBooleanType |
| 251 |
status; |
| 252 |
|
| 253 |
MagickWand |
| 254 |
*magick_wand; |
| 255 |
|
| 256 |
if (argc != 3) |
| 257 |
{ |
| 258 |
(void) fprintf(stdout,"Usage: %s image thumbnail\n",argv[0]); |
| 259 |
exit(0); |
| 260 |
} |
| 261 |
/* |
| 262 |
Read an image. |
| 263 |
*/ |
| 264 |
MagickWandGenesis(); |
| 265 |
magick_wand=NewMagickWand(); |
| 266 |
status=MagickReadImage(magick_wand,argv[1]); |
| 267 |
if (status == MagickFalse) |
| 268 |
ThrowWandException(magick_wand); |
| 269 |
/* |
| 270 |
Turn the images into a thumbnail sequence. |
| 271 |
*/ |
| 272 |
MagickResetIterator(magick_wand); |
| 273 |
while (MagickNextImage(magick_wand) != MagickFalse) |
| 274 |
MagickResizeImage(magick_wand,106,80,LanczosFilter,1.0); |
| 275 |
/* |
| 276 |
Write the image then destroy it. |
| 277 |
*/ |
| 278 |
status=MagickWriteImages(magick_wand,argv[2],MagickTrue); |
| 279 |
if (status == MagickFalse) |
| 280 |
ThrowWandException(magick_wand); |
| 281 |
magick_wand=DestroyMagickWand(magick_wand); |
| 282 |
MagickWandTerminus(); |
| 283 |
return(0); |
| 284 |
} |
| 285 |
</code></pre> |
| 286 |
|
| 287 |
<p>Here is another program that shows one way to get and set image pixels with the MagickWand API, <a href="https://imagemagick.org/source/contrast.c">contrast.c</a>. It reads an image, applies sigmoidal non-linearity contrast control, and writes the result to disk.</p> |
| 288 |
|
| 289 |
<pre class="overflow-auto p-3 mb-2 text-body-secondary bg-body-tertiary" style="max-height:75svh;"><code>#include <stdio.h> |
| 290 |
#include <stdlib.h> |
| 291 |
#include <math.h> |
| 292 |
#include <MagickWand/MagickWand.h> |
| 293 |
|
| 294 |
int main(int argc,char **argv) |
| 295 |
{ |
| 296 |
#define SigmoidalContrast(x) \ |
| 297 |
(QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503) |
| 298 |
#define ThrowWandException(wand) \ |
| 299 |
{ \ |
| 300 |
char \ |
| 301 |
*description; \ |
| 302 |
\ |
| 303 |
ExceptionType \ |
| 304 |
severity; \ |
| 305 |
\ |
| 306 |
description=MagickGetException(wand,&severity); \ |
| 307 |
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \ |
| 308 |
description=(char *) MagickRelinquishMemory(description); \ |
| 309 |
exit(-1); \ |
| 310 |
} |
| 311 |
|
| 312 |
long |
| 313 |
y; |
| 314 |
|
| 315 |
MagickBooleanType |
| 316 |
status; |
| 317 |
|
| 318 |
MagickWand |
| 319 |
*contrast_wand, |
| 320 |
*image_wand; |
| 321 |
|
| 322 |
PixelInfo |
| 323 |
pixel; |
| 324 |
|
| 325 |
PixelIterator |
| 326 |
*contrast_iterator, |
| 327 |
*iterator; |
| 328 |
|
| 329 |
PixelWand |
| 330 |
**contrast_pixels, |
| 331 |
**pixels; |
| 332 |
|
| 333 |
register long |
| 334 |
x; |
| 335 |
|
| 336 |
unsigned long |
| 337 |
width; |
| 338 |
|
| 339 |
if (argc != 3) |
| 340 |
{ |
| 341 |
(void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]); |
| 342 |
exit(0); |
| 343 |
} |
| 344 |
/* |
| 345 |
Read an image. |
| 346 |
*/ |
| 347 |
MagickWandGenesis(); |
| 348 |
image_wand=NewMagickWand(); |
| 349 |
status=MagickReadImage(image_wand,argv[1]); |
| 350 |
if (status == MagickFalse) |
| 351 |
ThrowWandException(image_wand); |
| 352 |
contrast_wand=CloneMagickWand(image_wand); |
| 353 |
/* |
| 354 |
Sigmoidal non-linearity contrast control. |
| 355 |
*/ |
| 356 |
iterator=NewPixelIterator(image_wand); |
| 357 |
contrast_iterator=NewPixelIterator(contrast_wand); |
| 358 |
if ((iterator == (PixelIterator *) NULL) || |
| 359 |
(contrast_iterator == (PixelIterator *) NULL)) |
| 360 |
ThrowWandException(image_wand); |
| 361 |
for (y=0; y < (long) MagickGetImageHeight(image_wand); y++) |
| 362 |
{ |
| 363 |
pixels=PixelGetNextIteratorRow(iterator,&width); |
| 364 |
contrast_pixels=PixelGetNextIteratorRow(contrast_iterator,&width); |
| 365 |
if ((pixels == (PixelWand **) NULL) || |
| 366 |
(contrast_pixels == (PixelWand **) NULL)) |
| 367 |
break; |
| 368 |
for (x=0; x < (long) width; x++) |
| 369 |
{ |
| 370 |
PixelGetMagickColor(pixels[x],&pixel); |
| 371 |
pixel.red=SigmoidalContrast(pixel.red); |
| 372 |
pixel.green=SigmoidalContrast(pixel.green); |
| 373 |
pixel.blue=SigmoidalContrast(pixel.blue); |
| 374 |
pixel.index=SigmoidalContrast(pixel.index); |
| 375 |
PixelSetPixelColor(contrast_pixels[x],&pixel); |
| 376 |
} |
| 377 |
(void) PixelSyncIterator(contrast_iterator); |
| 378 |
} |
| 379 |
if (y < (long) MagickGetImageHeight(image_wand)) |
| 380 |
ThrowWandException(image_wand); |
| 381 |
contrast_iterator=DestroyPixelIterator(contrast_iterator); |
| 382 |
iterator=DestroyPixelIterator(iterator); |
| 383 |
image_wand=DestroyMagickWand(image_wand); |
| 384 |
/* |
| 385 |
Write the image then destroy it. |
| 386 |
*/ |
| 387 |
status=MagickWriteImages(contrast_wand,argv[2],MagickTrue); |
| 388 |
if (status == MagickFalse) |
| 389 |
ThrowWandException(image_wand); |
| 390 |
contrast_wand=DestroyMagickWand(contrast_wand); |
| 391 |
MagickWandTerminus(); |
| 392 |
return(0); |
| 393 |
} |
| 394 |
</code></pre> |
| 395 |
<p><a class="anchor" id="wand-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://imagemagick.org/source/wand/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> |
| 396 |
|
| 397 |
<pre class="overflow-auto p-3 mb-2 text-body-secondary bg-body-tertiary" style="max-height:75svh;"><code>#include <stdio.h> |
| 398 |
#include <stdio.h> |
| 399 |
#include <stdlib.h> |
| 400 |
#include <math.h> |
| 401 |
#include <MagickWand/MagickWand.h> |
| 402 |
|
| 403 |
static MagickBooleanType SigmoidalContrast(WandView *contrast_view, |
| 404 |
const ssize_t y,const int thread_id,void *context) |
| 405 |
{ |
| 406 |
#define SigmoidalContrast(x) \ |
| 407 |
(QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503) |
| 408 |
|
| 409 |
PixelInfo |
| 410 |
pixel; |
| 411 |
|
| 412 |
PixelWand |
| 413 |
**pixels; |
| 414 |
|
| 415 |
RectangleInfo |
| 416 |
extent; |
| 417 |
|
| 418 |
register ssize_t |
| 419 |
x; |
| 420 |
|
| 421 |
extent=GetWandViewExtent(contrast_view); |
| 422 |
pixels=GetWandViewPixels(contrast_view); |
| 423 |
for (x=0; x < (ssize_t) extent.width; x++) |
| 424 |
{ |
| •425 |
PixelGetMagickColor(pixels[x],&pixel); |
| 426 |
pixel.red=SigmoidalContrast(pixel.red); |
| 427 |
pixel.green=SigmoidalContrast(pixel.green); |
| 428 |
pixel.blue=SigmoidalContrast(pixel.blue); |
| 429 |
pixel.index=SigmoidalContrast(pixel.index); |
| •430 |
PixelSetPixelColor(pixels[x],&pixel); |
| 431 |
} |
| 432 |
return(MagickTrue); |
| 433 |
} |
| 434 |
|
| 435 |
int main(int argc,char **argv) |
| 436 |
{ |
| 437 |
#define ThrowWandException(wand) \ |
| 438 |
{ \ |
| 439 |
char \ |
| 440 |
*description; \ |
| 441 |
\ |
| 442 |
ExceptionType \ |
| 443 |
severity; \ |
| 444 |
\ |
| 445 |
description=MagickGetException(wand,&severity); \ |
| 446 |
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \ |
| 447 |
description=(char *) MagickRelinquishMemory(description); \ |
| 448 |
exit(-1); \ |
| 449 |
} |
| 450 |
|
| 451 |
MagickBooleanType |
| 452 |
status; |
| 453 |
|
| 454 |
MagickWand |
| 455 |
*contrast_wand; |
| 456 |
|
| 457 |
PixelInfo |
| 458 |
pixel; |
| 459 |
|
| 460 |
WandView |
| 461 |
*contrast_view; |
| 462 |
|
| 463 |
if (argc != 3) |
| 464 |
{ |
| 465 |
(void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]); |
| 466 |
exit(0); |
| 467 |
} |
| 468 |
/* |
| 469 |
Read an image. |
| 470 |
*/ |
| 471 |
MagickWandGenesis(); |
| 472 |
contrast_wand=NewMagickWand(); |
| 473 |
status=MagickReadImage(contrast_wand,argv[1]); |
| 474 |
if (status == MagickFalse) |
| 475 |
ThrowWandException(contrast_wand); |
| 476 |
/* |
| 477 |
Sigmoidal non-linearity contrast control. |
| 478 |
*/ |
| 479 |
contrast_view=NewWandView(contrast_wand); |
| 480 |
if (contrast_view == (WandView *) NULL) |
| 481 |
ThrowWandException(contrast_wand); |
| 482 |
status=UpdateWandViewIterator(contrast_view,SigmoidalContrast,(void *) NULL); |
| 483 |
if (status == MagickFalse) |
| 484 |
ThrowWandException(contrast_wand); |
| 485 |
contrast_view=DestroyWandView(contrast_view); |
| 486 |
/* |
| 487 |
Write the image then destroy it. |
| 488 |
*/ |
| 489 |
status=MagickWriteImages(contrast_wand,argv[2],MagickTrue); |
| 490 |
if (status == MagickFalse) |
| 491 |
ThrowWandException(contrast_wand); |
| 492 |
contrast_wand=DestroyMagickWand(contrast_wand); |
| 493 |
MagickWandTerminus(); |
| 494 |
return(0); |
| 495 |
} |
| 496 |
</code></pre> |
| 497 |
<p><code>MagickWandTerminus()</code> is a function in the ImageMagick library that is used to clean up and release resources when shutting down an application that uses ImageMagick. This function should be called in the primary thread of the application's process during the shutdown process. It's crucial that this function is invoked only after any threads that are using ImageMagick functions have terminated.</p> |
| 498 |
|
| 499 |
<p>ImageMagick might internally use threads via OpenMP (a method for parallel programming). As a result, it's important to ensure that any function calls into ImageMagick have completed before calling <code>MagickWandTerminus()</code>. This prevents issues with OpenMP worker threads accessing resources that are destroyed by this termination function.</p> |
| 500 |
|
| 501 |
<p>If OpenMP is being used (starting from version 5.0), the OpenMP implementation itself handles starting and stopping worker threads and allocating and freeing resources using its own methods. This means that after calling <code>MagickWandTerminus()</code>, some OpenMP resources and worker threads might still remain allocated. To address this, the function <code>omp_pause_resource_all(omp_pause_hard)</code> can be invoked. This function, introduced in OpenMP version 5.0, ensures that any resources allocated by OpenMP (such as threads and thread-specific memory) are freed. It's recommended to call this function after <code>MagickWandTerminus()</code> has completed its execution.</p> |
| 502 |
</div> |
| 503 |
|
| 504 |
</div> |
| 505 |
<div class="col-md-3"> |
| 506 |
<div class="container text-center my-3"> |
| 507 |
<a href="../image/wizard.png" rel="noopener noreferrer" target="_blank"> |
| •508 |
<img alt="The Tao of the Spiritual Warrior" class="img-fluid img-thumbnail" height="1468" loading="lazy" src="../image/wizard.png" width="1104" /> |
| 509 |
</a> |
| 510 |
<p class="mt-2"><iframe src="https://github.com/sponsors/ImageMagick/button" title="Sponsor ImageMagick" height="35" width="107" style="border: 0;"></iframe></p> |
| 511 |
</div> |
| 512 |
<div class="container text-center my-3"> |
| •513 |
<script async="true" src="https://localhost/pagead/js/adsbygoogle.js?client=ca-pub-3129977114552745" |
| 514 |
crossorigin="anonymous"></script> |
| 515 |
|
| 516 |
<ins class="adsbygoogle" |
| 517 |
style="display:block" |
| 518 |
data-ad-client="ca-pub-3129977114552745" |
| 519 |
data-ad-slot="1083537442" |
| 520 |
data-ad-format="auto" |
| 521 |
data-full-width-responsive="true"></ins> |
| 522 |
<script> |
| 523 |
(adsbygoogle = window.adsbygoogle || []).push({}); |
| 524 |
</script> |
| 525 |
</div> |
| 526 |
</div> |
| 527 |
</div> |
| 528 |
<a aria-label="About ImageMagick" class="btn btn-outline-warning mt-3" href="../index-2.html">About ImageMagick</a> |
| 529 |
</main> |
| 530 |
<footer class="text-center pt-5 my-5 text-body-secondary border-top"> |
| 531 |
<div class="container-fluid"> |
| 532 |
<a href="../security-policy/index.html">Security</a> • |
| 533 |
<a href="../news/index.html">News</a> |
| •534 |
|
| 535 |
<a href="#"><img class="d-inline" id="wand" alt="And Now a Touch of Magick" width="16" height="16" src="../image/wand.ico" /></a> |
| 536 |
|
| 537 |
<a href="../links/index.html">Related</a> • |
| 538 |
<a href="../sitemap/index.html">Sitemap</a> |
| •539 |
<br /> |
| 540 |
<a href="../support/index.html">Sponsor</a> • |
| 541 |
<a href="../cite/index.html">Cite</a> • |
| 542 |
<a href="http://pgp.mit.edu/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> • |
| 543 |
<a href="https://github.com/ImageMagick/ImageMagick/discussions">Contact Us</a> |
| •544 |
<br /> |
| 545 |
<a href="https://github.com/imagemagick/imagemagick" rel="noopener noreferrer" target="_blank" aria-label="GitHub"><svg xmlns="http://www.w3.org/2000/svg" class="navbar-nav-svg" viewBox="0 0 512 499.36" width="2%" height="2%" role="img" focusable="false"> |
| 546 |
<title>GitHub</title> |
| 547 |
<path fill="currentColor" fill-rule="evenodd" d="M256 0C114.64 0 0 114.61 0 256c0 113.09 73.34 209 175.08 242.9 12.8 2.35 17.47-5.56 17.47-12.34 0-6.08-.22-22.18-.35-43.54-71.2 15.49-86.2-34.34-86.2-34.34-11.64-29.57-28.42-37.45-28.42-37.45-23.27-15.84 1.73-15.55 1.73-15.55 25.69 1.81 39.21 26.38 39.21 26.38 22.84 39.12 59.92 27.82 74.5 21.27 2.33-16.54 8.94-27.82 16.25-34.22-56.84-6.43-116.6-28.43-116.6-126.49 0-27.95 10-50.8 26.35-68.69-2.63-6.48-11.42-32.5 2.51-67.75 0 0 21.49-6.88 70.4 26.24a242.65 242.65 0 0 1 128.18 0c48.87-33.13 70.33-26.24 70.33-26.24 14 35.25 5.18 61.27 2.55 67.75 16.41 17.9 26.31 40.75 26.31 68.69 0 98.35-59.85 120-116.88 126.32 9.19 7.9 17.38 23.53 17.38 47.41 0 34.22-.31 61.83-.31 70.23 0 6.85 4.61 14.81 17.6 12.31C438.72 464.97 512 369.08 512 256.02 512 114.62 397.37 0 256 0z" /> |
| 548 |
</svg></a> • |
| 549 |
<a href="https://twitter.com/imagemagick" rel="noopener noreferrer" target="_blank" aria-label="Twitter"><svg xmlns="http://www.w3.org/2000/svg" class="navbar-nav-svg" viewBox="0 0 300 300" width="2%" height="2%" role="img" focusable="false"> |
| 550 |
<title>Twitter</title> |
| 551 |
<path d="M178.57 127.15 290.27 0h-26.46l-97.03 110.38L89.34 0H0l117.13 166.93L0 300.25h26.46l102.4-116.59 81.8 116.59h89.34M36.01 19.54H76.66l187.13 262.13h-40.66" /> |
| 552 |
</svg></a> |
| •553 |
<br /> |
| 554 |
<small>Copyright © 1999 ImageMagick Studio LLC</small> |
| 555 |
</div> |
| 556 |
</footer> |
| 557 |
<div style="visibility: hidden;"> |
| 558 |
<div class="gcse-search"></div> |
| 559 |
</div> |
| 560 |
</div> |
| 561 |
|
| 562 |
|
| 563 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script> |
| 564 |
</body> |
| 565 |
|
| 566 |
|
| 567 |
</html> |