blob: 15255b916ac7b65d29aea65bd60882b0c20ddb81 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4//
5// Implementation of Image
6//
7
8#define MAGICKCORE_IMPLEMENTATION 1
9#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
10
cristy3ed852e2009-09-05 21:47:34 +000011#include <cstdlib>
12#include <string>
13#include <string.h>
14#include <errno.h>
15#include <math.h>
cristy4c08aed2011-07-01 19:47:50 +000016#include "Magick++/Include.h"
cristy3ed852e2009-09-05 21:47:34 +000017
18using namespace std;
19
20#include "Magick++/Image.h"
21#include "Magick++/Functions.h"
22#include "Magick++/Pixels.h"
23#include "Magick++/Options.h"
24#include "Magick++/ImageRef.h"
25
26#define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
cristy3ed852e2009-09-05 21:47:34 +000027#define DegreesToRadians(x) (MagickPI*(x)/180.0)
28
29MagickDLLDeclExtern const char *Magick::borderGeometryDefault = "6x6+0+0";
30MagickDLLDeclExtern const char *Magick::frameGeometryDefault = "25x25+6+6";
31MagickDLLDeclExtern const char *Magick::raiseGeometryDefault = "6x6+0+0";
32
33static bool magick_initialized=false;
34
35//
36// Explicit template instantiations
37//
38
39//
40// Friend functions to compare Image objects
41//
42
cristy4e0eef02010-05-30 21:52:21 +000043MagickDLLDecl int Magick::operator == ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000044 const Magick::Image& right_ )
45{
46 // If image pixels and signature are the same, then the image is identical
47 return ( ( left_.rows() == right_.rows() ) &&
48 ( left_.columns() == right_.columns() ) &&
49 ( left_.signature() == right_.signature() )
50 );
51}
cristy4e0eef02010-05-30 21:52:21 +000052MagickDLLDecl int Magick::operator != ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000053 const Magick::Image& right_ )
54{
55 return ( ! (left_ == right_) );
56}
cristy4e0eef02010-05-30 21:52:21 +000057MagickDLLDecl int Magick::operator > ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000058 const Magick::Image& right_ )
59{
60 return ( !( left_ < right_ ) && ( left_ != right_ ) );
61}
cristy4e0eef02010-05-30 21:52:21 +000062MagickDLLDecl int Magick::operator < ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000063 const Magick::Image& right_ )
64{
65 // If image pixels are less, then image is smaller
66 return ( ( left_.rows() * left_.columns() ) <
67 ( right_.rows() * right_.columns() )
68 );
69}
cristy4e0eef02010-05-30 21:52:21 +000070MagickDLLDecl int Magick::operator >= ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000071 const Magick::Image& right_ )
72{
73 return ( ( left_ > right_ ) || ( left_ == right_ ) );
74}
cristy4e0eef02010-05-30 21:52:21 +000075MagickDLLDecl int Magick::operator <= ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000076 const Magick::Image& right_ )
77{
78 return ( ( left_ < right_ ) || ( left_ == right_ ) );
79}
80
81//
82// Image object implementation
83//
84
85// Construct from image file or image specification
86Magick::Image::Image( const std::string &imageSpec_ )
87 : _imgRef(new ImageRef)
88{
89 try
90 {
91 // Initialize, Allocate and Read images
92 read( imageSpec_ );
93 }
94 catch ( const Warning & /*warning_*/ )
95 {
96 // FIXME: need a way to report warnings in constructor
97 }
98 catch ( const Error & /*error_*/ )
99 {
100 // Release resources
101 delete _imgRef;
102 throw;
103 }
104}
105
106// Construct a blank image canvas of specified size and color
107Magick::Image::Image( const Geometry &size_,
108 const Color &color_ )
109 : _imgRef(new ImageRef)
110{
111 // xc: prefix specifies an X11 color string
112 std::string imageSpec("xc:");
113 imageSpec += color_;
114
115 try
116 {
117 // Set image size
118 size( size_ );
119
120 // Initialize, Allocate and Read images
121 read( imageSpec );
122 }
123 catch ( const Warning & /*warning_*/ )
124 {
125 // FIXME: need a way to report warnings in constructor
126 }
127 catch ( const Error & /*error_*/ )
128 {
129 // Release resources
130 delete _imgRef;
131 throw;
132 }
133}
134
135// Construct Image from in-memory BLOB
136Magick::Image::Image ( const Blob &blob_ )
137 : _imgRef(new ImageRef)
138{
139 try
140 {
141 // Initialize, Allocate and Read images
142 read( blob_ );
143 }
144 catch ( const Warning & /*warning_*/ )
145 {
146 // FIXME: need a way to report warnings in constructor
147 }
148 catch ( const Error & /*error_*/ )
149 {
150 // Release resources
151 delete _imgRef;
152 throw;
153 }
154}
155
156// Construct Image of specified size from in-memory BLOB
157Magick::Image::Image ( const Blob &blob_,
158 const Geometry &size_ )
159 : _imgRef(new ImageRef)
160{
161 try
162 {
163 // Read from Blob
164 read( blob_, size_ );
165 }
166 catch ( const Warning & /*warning_*/ )
167 {
168 // FIXME: need a way to report warnings in constructor
169 }
170 catch ( const Error & /*error_*/ )
171 {
172 // Release resources
173 delete _imgRef;
174 throw;
175 }
176}
177
178// Construct Image of specified size and depth from in-memory BLOB
179Magick::Image::Image ( const Blob &blob_,
180 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +0000181 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +0000182 : _imgRef(new ImageRef)
183{
184 try
185 {
186 // Read from Blob
187 read( blob_, size_, depth_ );
188 }
189 catch ( const Warning & /*warning_*/ )
190 {
191 // FIXME: need a way to report warnings in constructor
192 }
193 catch ( const Error & /*error_*/ )
194 {
195 // Release resources
196 delete _imgRef;
197 throw;
198 }
199}
200
201// Construct Image of specified size, depth, and format from in-memory BLOB
202Magick::Image::Image ( const Blob &blob_,
203 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +0000204 const size_t depth_,
cristy3ed852e2009-09-05 21:47:34 +0000205 const std::string &magick_ )
206 : _imgRef(new ImageRef)
207{
208 try
209 {
210 // Read from Blob
211 read( blob_, size_, depth_, magick_ );
212 }
213 catch ( const Warning & /*warning_*/ )
214 {
215 // FIXME: need a way to report warnings in constructor
216 }
217 catch ( const Error & /*error_*/ )
218 {
219 // Release resources
220 delete _imgRef;
221 throw;
222 }
223}
224
225// Construct Image of specified size, and format from in-memory BLOB
226Magick::Image::Image ( const Blob &blob_,
227 const Geometry &size_,
228 const std::string &magick_ )
229 : _imgRef(new ImageRef)
230{
231 try
232 {
233 // Read from Blob
234 read( blob_, size_, magick_ );
235 }
236 catch ( const Warning & /*warning_*/ )
237 {
238 // FIXME: need a way to report warnings in constructor
239 }
240 catch ( const Error & /*error_*/ )
241 {
242 // Release resources
243 delete _imgRef;
244 throw;
245 }
246}
247
248// Construct an image based on an array of raw pixels, of specified
249// type and mapping, in memory
cristyeaedf062010-05-29 22:36:02 +0000250Magick::Image::Image ( const size_t width_,
251 const size_t height_,
cristy3ed852e2009-09-05 21:47:34 +0000252 const std::string &map_,
253 const StorageType type_,
254 const void *pixels_ )
255 : _imgRef(new ImageRef)
256{
257 try
258 {
259 read( width_, height_, map_.c_str(), type_, pixels_ );
260 }
261 catch ( const Warning & /*warning_*/ )
262 {
263 // FIXME: need a way to report warnings in constructor
264 }
265 catch ( const Error & /*error_*/ )
266 {
267 // Release resources
268 delete _imgRef;
269 throw;
270 }
271}
272
273// Default constructor
274Magick::Image::Image( void )
275 : _imgRef(new ImageRef)
276{
277}
278
279// Destructor
280/* virtual */
281Magick::Image::~Image()
282{
283 bool doDelete = false;
284 {
285 Lock( &_imgRef->_mutexLock );
286 if ( --_imgRef->_refCount == 0 )
287 doDelete = true;
288 }
289
290 if ( doDelete )
291 {
292 delete _imgRef;
293 }
294 _imgRef = 0;
295}
296
297// Adaptive-blur image
298void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
299{
300 ExceptionInfo exceptionInfo;
301 GetExceptionInfo( &exceptionInfo );
302 MagickCore::Image* newImage =
303 AdaptiveBlurImage( image(), radius_, sigma_, &exceptionInfo);
304 replaceImage( newImage );
305 throwException( exceptionInfo );
306 (void) DestroyExceptionInfo( &exceptionInfo );
307}
308
309// Local adaptive threshold image
310// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
311// Width x height define the size of the pixel neighborhood
312// offset = constant to subtract from pixel neighborhood mean
cristyeaedf062010-05-29 22:36:02 +0000313void Magick::Image::adaptiveThreshold ( const size_t width_,
314 const size_t height_,
cristy4e0eef02010-05-30 21:52:21 +0000315 const ssize_t offset_ )
cristy3ed852e2009-09-05 21:47:34 +0000316{
317 ExceptionInfo exceptionInfo;
318 GetExceptionInfo( &exceptionInfo );
319 MagickCore::Image* newImage =
320 AdaptiveThresholdImage( constImage(), width_, height_, offset_, &exceptionInfo );
321 replaceImage( newImage );
322 throwException( exceptionInfo );
323 (void) DestroyExceptionInfo( &exceptionInfo );
324}
325
326// Add noise to image
327void Magick::Image::addNoise( const NoiseType noiseType_ )
328{
329 ExceptionInfo exceptionInfo;
330 GetExceptionInfo( &exceptionInfo );
331 MagickCore::Image* newImage =
332 AddNoiseImage ( image(),
333 noiseType_,
334 &exceptionInfo );
335 replaceImage( newImage );
336 throwException( exceptionInfo );
337 (void) DestroyExceptionInfo( &exceptionInfo );
338}
339
340void Magick::Image::addNoiseChannel( const ChannelType channel_,
341 const NoiseType noiseType_ )
342{
343 ExceptionInfo exceptionInfo;
344 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +0000345 PushPixelChannelMap( image(), channel_);
cristy3ed852e2009-09-05 21:47:34 +0000346 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +0000347 AddNoiseImage ( image(),
cristy3ed852e2009-09-05 21:47:34 +0000348 noiseType_,
349 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +0000350 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +0000351 replaceImage( newImage );
352 throwException( exceptionInfo );
353 (void) DestroyExceptionInfo( &exceptionInfo );
354}
355
356// Affine Transform image
357void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
358{
359 ExceptionInfo exceptionInfo;
360 GetExceptionInfo( &exceptionInfo );
361
362 AffineMatrix _affine;
363 _affine.sx = affine_.sx();
364 _affine.sy = affine_.sy();
365 _affine.rx = affine_.rx();
366 _affine.ry = affine_.ry();
367 _affine.tx = affine_.tx();
368 _affine.ty = affine_.ty();
369
370 MagickCore::Image* newImage =
371 AffineTransformImage( image(), &_affine, &exceptionInfo);
372 replaceImage( newImage );
373 throwException( exceptionInfo );
374 (void) DestroyExceptionInfo( &exceptionInfo );
375}
376
377// Annotate using specified text, and placement location
378void Magick::Image::annotate ( const std::string &text_,
379 const Geometry &location_ )
380{
381 annotate ( text_, location_, NorthWestGravity, 0.0 );
382}
383// Annotate using specified text, bounding area, and placement gravity
384void Magick::Image::annotate ( const std::string &text_,
385 const Geometry &boundingArea_,
386 const GravityType gravity_ )
387{
388 annotate ( text_, boundingArea_, gravity_, 0.0 );
389}
390// Annotate with text using specified text, bounding area, placement
391// gravity, and rotation.
392void Magick::Image::annotate ( const std::string &text_,
393 const Geometry &boundingArea_,
394 const GravityType gravity_,
395 const double degrees_ )
396{
397 modifyImage();
398
399 DrawInfo *drawInfo
400 = options()->drawInfo();
401
402 drawInfo->text = const_cast<char *>(text_.c_str());
403
404 char boundingArea[MaxTextExtent];
405
406 drawInfo->geometry = 0;
407 if ( boundingArea_.isValid() ){
408 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
409 {
cristyb51dff52011-05-19 16:55:47 +0000410 FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
cristyfe0019b2010-06-07 02:23:32 +0000411 (double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
cristy3ed852e2009-09-05 21:47:34 +0000412 }
413 else
414 {
415 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
416 MaxTextExtent);
417 }
418 drawInfo->geometry = boundingArea;
419 }
420
421 drawInfo->gravity = gravity_;
422
423 AffineMatrix oaffine = drawInfo->affine;
424 if ( degrees_ != 0.0)
425 {
426 AffineMatrix affine;
427 affine.sx=1.0;
428 affine.rx=0.0;
429 affine.ry=0.0;
430 affine.sy=1.0;
431 affine.tx=0.0;
432 affine.ty=0.0;
433
434 AffineMatrix current = drawInfo->affine;
435 affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
436 affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
437 affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
438 affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
439
440 drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
441 drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
442 drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
443 drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
444 drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
445 +current.tx;
446 }
447
448 AnnotateImage( image(), drawInfo );
449
450 // Restore original values
451 drawInfo->affine = oaffine;
452 drawInfo->text = 0;
453 drawInfo->geometry = 0;
454
455 throwImageException();
456}
457// Annotate with text (bounding area is entire image) and placement gravity.
458void Magick::Image::annotate ( const std::string &text_,
459 const GravityType gravity_ )
460{
461 modifyImage();
462
463 DrawInfo *drawInfo
464 = options()->drawInfo();
465
466 drawInfo->text = const_cast<char *>(text_.c_str());
467
468 drawInfo->gravity = gravity_;
469
470 AnnotateImage( image(), drawInfo );
471
472 drawInfo->gravity = NorthWestGravity;
473 drawInfo->text = 0;
474
475 throwImageException();
476}
477
478// Blur image
479void Magick::Image::blur( const double radius_, const double sigma_ )
480{
481 ExceptionInfo exceptionInfo;
482 GetExceptionInfo( &exceptionInfo );
483 MagickCore::Image* newImage =
484 BlurImage( image(), radius_, sigma_, &exceptionInfo);
485 replaceImage( newImage );
486 throwException( exceptionInfo );
487 (void) DestroyExceptionInfo( &exceptionInfo );
488}
489
490void Magick::Image::blurChannel( const ChannelType channel_,
491 const double radius_, const double sigma_ )
492{
493 ExceptionInfo exceptionInfo;
494 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +0000495 PushPixelChannelMap( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +0000496 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +0000497 BlurImage( image(), radius_, sigma_, &exceptionInfo);
cristyed231572011-07-14 02:18:59 +0000498 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +0000499 replaceImage( newImage );
500 throwException( exceptionInfo );
501 (void) DestroyExceptionInfo( &exceptionInfo );
502}
503
504// Add border to image
505// Only uses width & height
506void Magick::Image::border( const Geometry &geometry_ )
507{
508 RectangleInfo borderInfo = geometry_;
509 ExceptionInfo exceptionInfo;
510 GetExceptionInfo( &exceptionInfo );
511 MagickCore::Image* newImage =
512 BorderImage( image(), &borderInfo, &exceptionInfo);
513 replaceImage( newImage );
514 throwException( exceptionInfo );
515 (void) DestroyExceptionInfo( &exceptionInfo );
516}
517
518// Extract channel from image
519void Magick::Image::channel ( const ChannelType channel_ )
520{
521 modifyImage();
cristyed231572011-07-14 02:18:59 +0000522 PushPixelChannelMap( image(), channel_ );
cristy3139dc22011-07-08 00:11:42 +0000523 SeparateImage ( image() );
cristyed231572011-07-14 02:18:59 +0000524 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +0000525 throwImageException();
526}
527
528// Set or obtain modulus channel depth
cristyfefab1b2011-07-05 00:33:22 +0000529void Magick::Image::channelDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +0000530{
531 modifyImage();
cristyfefab1b2011-07-05 00:33:22 +0000532 SetImageDepth( image(), depth_);
cristy3ed852e2009-09-05 21:47:34 +0000533 throwImageException();
534}
cristyfefab1b2011-07-05 00:33:22 +0000535size_t Magick::Image::channelDepth ( )
cristy3ed852e2009-09-05 21:47:34 +0000536{
cristyeaedf062010-05-29 22:36:02 +0000537 size_t channel_depth;
cristy3ed852e2009-09-05 21:47:34 +0000538
539 ExceptionInfo exceptionInfo;
540 GetExceptionInfo( &exceptionInfo );
cristyfefab1b2011-07-05 00:33:22 +0000541 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000542 throwException( exceptionInfo );
543 (void) DestroyExceptionInfo( &exceptionInfo );
544 return channel_depth;
545}
546
547
548// Charcoal-effect image
549void Magick::Image::charcoal( const double radius_, const double sigma_ )
550{
551 ExceptionInfo exceptionInfo;
552 GetExceptionInfo( &exceptionInfo );
553 MagickCore::Image* newImage =
554 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
555 replaceImage( newImage );
556 throwException( exceptionInfo );
557 (void) DestroyExceptionInfo( &exceptionInfo );
558}
559
560// Chop image
561void Magick::Image::chop( const Geometry &geometry_ )
562{
563 RectangleInfo chopInfo = geometry_;
564 ExceptionInfo exceptionInfo;
565 GetExceptionInfo( &exceptionInfo );
566 MagickCore::Image* newImage =
567 ChopImage( image(), &chopInfo, &exceptionInfo);
568 replaceImage( newImage );
569 throwException( exceptionInfo );
570 (void) DestroyExceptionInfo( &exceptionInfo );
571}
572
cristyb32b90a2009-09-07 21:45:48 +0000573// contains one or more color corrections and applies the correction to the
574// image.
575void Magick::Image::cdl ( const std::string &cdl_ )
576{
577 modifyImage();
cristy1bfa9f02011-08-11 02:35:43 +0000578 ExceptionInfo exceptionInfo;
579 GetExceptionInfo( &exceptionInfo );
580 (void) ColorDecisionListImage( image(), cdl_.c_str(), &exceptionInfo );
581 throwException( exceptionInfo );
582 (void) DestroyExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +0000583}
584
cristy3ed852e2009-09-05 21:47:34 +0000585// Colorize
cristy4c08aed2011-07-01 19:47:50 +0000586void Magick::Image::colorize ( const unsigned int alphaRed_,
587 const unsigned int alphaGreen_,
588 const unsigned int alphaBlue_,
cristy3ed852e2009-09-05 21:47:34 +0000589 const Color &penColor_ )
590{
591 if ( !penColor_.isValid() )
592 {
593 throwExceptionExplicit( OptionError,
594 "Pen color argument is invalid");
595 }
596
cristy4c08aed2011-07-01 19:47:50 +0000597 char alpha[MaxTextExtent];
598 FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
cristy3ed852e2009-09-05 21:47:34 +0000599
600 ExceptionInfo exceptionInfo;
601 GetExceptionInfo( &exceptionInfo );
602 MagickCore::Image* newImage =
cristy4c08aed2011-07-01 19:47:50 +0000603 ColorizeImage ( image(), alpha,
cristy3ed852e2009-09-05 21:47:34 +0000604 penColor_, &exceptionInfo );
605 replaceImage( newImage );
606 throwException( exceptionInfo );
607 (void) DestroyExceptionInfo( &exceptionInfo );
608}
cristy4c08aed2011-07-01 19:47:50 +0000609void Magick::Image::colorize ( const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000610 const Color &penColor_ )
611{
cristy4c08aed2011-07-01 19:47:50 +0000612 colorize( alpha_, alpha_, alpha_, penColor_ );
cristy3ed852e2009-09-05 21:47:34 +0000613}
614
cristy735e8942010-04-02 20:32:57 +0000615// Apply a color matrix to the image channels. The user supplied
616// matrix may be of order 1 to 6 (1x1 through 6x6).
cristyeaedf062010-05-29 22:36:02 +0000617void Magick::Image::colorMatrix (const size_t order_,
cristyc8918bb2010-04-03 01:57:27 +0000618 const double *color_matrix_)
cristy735e8942010-04-02 20:32:57 +0000619{
cristyc8918bb2010-04-03 01:57:27 +0000620 KernelInfo
621 *kernel_info;
622
cristy735e8942010-04-02 20:32:57 +0000623 ExceptionInfo exceptionInfo;
624 GetExceptionInfo( &exceptionInfo );
cristy5e6be1e2011-07-16 01:23:39 +0000625 kernel_info=AcquireKernelInfo((const char *) NULL);
cristyc8918bb2010-04-03 01:57:27 +0000626 kernel_info->width=order_;
627 kernel_info->height=order_;
cristyc8918bb2010-04-03 01:57:27 +0000628 kernel_info->values=(double *) color_matrix_;
cristy735e8942010-04-02 20:32:57 +0000629 MagickCore::Image* newImage =
cristyc8918bb2010-04-03 01:57:27 +0000630 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
cristya2175d32010-04-03 02:25:17 +0000631 kernel_info->values=(double *) NULL;
cristyc8918bb2010-04-03 01:57:27 +0000632 kernel_info=DestroyKernelInfo(kernel_info);
cristy735e8942010-04-02 20:32:57 +0000633 replaceImage( newImage );
634 throwException( exceptionInfo );
635 (void) DestroyExceptionInfo( &exceptionInfo );
636}
637
cristy3ed852e2009-09-05 21:47:34 +0000638// Compare current image with another image
639// Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
640// in the current image. False is returned if the images are identical.
641bool Magick::Image::compare ( const Image &reference_ )
642{
643 modifyImage();
644 Image ref = reference_;
645 ref.modifyImage();
646 return static_cast<bool>(IsImagesEqual(image(), ref.image()));
647}
648
649// Composite two images
650void Magick::Image::composite ( const Image &compositeImage_,
cristyd99b0962010-05-29 23:14:26 +0000651 const ssize_t xOffset_,
652 const ssize_t yOffset_,
cristy3ed852e2009-09-05 21:47:34 +0000653 const CompositeOperator compose_ )
654{
655 // Image supplied as compositeImage is composited with current image and
656 // results in updating current image.
657 modifyImage();
658
659 CompositeImage( image(),
660 compose_,
661 compositeImage_.constImage(),
662 xOffset_,
663 yOffset_ );
664 throwImageException();
665}
666void Magick::Image::composite ( const Image &compositeImage_,
667 const Geometry &offset_,
668 const CompositeOperator compose_ )
669{
670 modifyImage();
671
cristybb503372010-05-27 20:51:26 +0000672 ssize_t x = offset_.xOff();
673 ssize_t y = offset_.yOff();
674 size_t width = columns();
675 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +0000676
677 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
678 &x, &y,
679 &width, &height );
680
681 CompositeImage( image(),
682 compose_,
683 compositeImage_.constImage(),
684 x, y );
685 throwImageException();
686}
687void Magick::Image::composite ( const Image &compositeImage_,
688 const GravityType gravity_,
689 const CompositeOperator compose_ )
690{
691 modifyImage();
692
693 RectangleInfo geometry;
694
695 SetGeometry(compositeImage_.constImage(), &geometry);
696 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
697
698 CompositeImage( image(),
699 compose_,
700 compositeImage_.constImage(),
701 geometry.x, geometry.y );
702 throwImageException();
703}
704
705// Contrast image
cristyeaedf062010-05-29 22:36:02 +0000706void Magick::Image::contrast ( const size_t sharpen_ )
cristy3ed852e2009-09-05 21:47:34 +0000707{
708 modifyImage();
709 ContrastImage ( image(), (MagickBooleanType) sharpen_ );
710 throwImageException();
711}
712
713// Convolve image. Applies a general image convolution kernel to the image.
714// order_ represents the number of columns and rows in the filter kernel.
715// kernel_ is an array of doubles representing the convolution kernel.
cristyeaedf062010-05-29 22:36:02 +0000716void Magick::Image::convolve ( const size_t order_,
cristy3ed852e2009-09-05 21:47:34 +0000717 const double *kernel_ )
718{
cristy5e6be1e2011-07-16 01:23:39 +0000719 KernelInfo
720 *kernel_info;
721
cristy3ed852e2009-09-05 21:47:34 +0000722 ExceptionInfo exceptionInfo;
723 GetExceptionInfo( &exceptionInfo );
cristy5e6be1e2011-07-16 01:23:39 +0000724 kernel_info=AcquireKernelInfo((const char *) NULL);
725 kernel_info->width=order_;
726 kernel_info->height=order_;
727 kernel_info->values=(double *) kernel_;
cristy0a922382011-07-16 15:30:34 +0000728 kernel_info->bias=image()->bias;
cristy3ed852e2009-09-05 21:47:34 +0000729 MagickCore::Image* newImage =
cristy5e6be1e2011-07-16 01:23:39 +0000730 ConvolveImage ( image(), kernel_info, &exceptionInfo );
731 kernel_info->values=(double *) NULL;
732 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +0000733 replaceImage( newImage );
734 throwException( exceptionInfo );
735 (void) DestroyExceptionInfo( &exceptionInfo );
736}
737
738// Crop image
739void Magick::Image::crop ( const Geometry &geometry_ )
740{
741 RectangleInfo cropInfo = geometry_;
742 ExceptionInfo exceptionInfo;
743 GetExceptionInfo( &exceptionInfo );
744 MagickCore::Image* newImage =
745 CropImage( image(),
746 &cropInfo,
747 &exceptionInfo);
748 replaceImage( newImage );
749 throwException( exceptionInfo );
750 (void) DestroyExceptionInfo( &exceptionInfo );
751}
752
753// Cycle Color Map
cristyd99b0962010-05-29 23:14:26 +0000754void Magick::Image::cycleColormap ( const ssize_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +0000755{
756 modifyImage();
757 CycleColormapImage( image(), amount_ );
758 throwImageException();
759}
760
761// Despeckle
762void Magick::Image::despeckle ( void )
763{
764 ExceptionInfo exceptionInfo;
765 GetExceptionInfo( &exceptionInfo );
766 MagickCore::Image* newImage =
767 DespeckleImage( image(), &exceptionInfo );
768 replaceImage( newImage );
769 throwException( exceptionInfo );
770 (void) DestroyExceptionInfo( &exceptionInfo );
771}
772
773// Display image
774void Magick::Image::display( void )
775{
776 DisplayImages( imageInfo(), image() );
777}
778
779// Distort image. distorts an image using various distortion methods, by
780// mapping color lookups of the source image to a new destination image
781// usally of the same size as the source image, unless 'bestfit' is set to
782// true.
cristyb32b90a2009-09-07 21:45:48 +0000783void Magick::Image::distort ( const DistortImageMethod method_,
cristybb503372010-05-27 20:51:26 +0000784 const size_t number_arguments_,
cristyb32b90a2009-09-07 21:45:48 +0000785 const double *arguments_,
786 const bool bestfit_ )
cristy3ed852e2009-09-05 21:47:34 +0000787{
788 ExceptionInfo exceptionInfo;
789 GetExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +0000790 MagickCore::Image* newImage = DistortImage ( image(), method_,
791 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
792 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000793 replaceImage( newImage );
794 throwException( exceptionInfo );
795 (void) DestroyExceptionInfo( &exceptionInfo );
796}
797
798// Draw on image using single drawable
799void Magick::Image::draw ( const Magick::Drawable &drawable_ )
800{
801 modifyImage();
802
803 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
804
805 if(wand)
806 {
807 drawable_.operator()(wand);
808
809 if( constImage()->exception.severity == UndefinedException)
810 DrawRender(wand);
811
812 wand=DestroyDrawingWand(wand);
813 }
814
815 throwImageException();
816}
817
818// Draw on image using a drawable list
819void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
820{
821 modifyImage();
822
823 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
824
825 if(wand)
826 {
827 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
828 p != drawable_.end(); p++ )
829 {
830 p->operator()(wand);
831 if( constImage()->exception.severity != UndefinedException)
832 break;
833 }
834
835 if( constImage()->exception.severity == UndefinedException)
836 DrawRender(wand);
837
838 wand=DestroyDrawingWand(wand);
839 }
840
841 throwImageException();
842}
843
844// Hilight edges in image
845void Magick::Image::edge ( const double radius_ )
846{
847 ExceptionInfo exceptionInfo;
848 GetExceptionInfo( &exceptionInfo );
849 MagickCore::Image* newImage =
850 EdgeImage( image(), radius_, &exceptionInfo );
851 replaceImage( newImage );
852 throwException( exceptionInfo );
853 (void) DestroyExceptionInfo( &exceptionInfo );
854}
855
856// Emboss image (hilight edges)
857void Magick::Image::emboss ( const double radius_, const double sigma_ )
858{
859 ExceptionInfo exceptionInfo;
860 GetExceptionInfo( &exceptionInfo );
861 MagickCore::Image* newImage =
862 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
863 replaceImage( newImage );
864 throwException( exceptionInfo );
865 (void) DestroyExceptionInfo( &exceptionInfo );
866}
867
868// Enhance image (minimize noise)
869void Magick::Image::enhance ( void )
870{
871 ExceptionInfo exceptionInfo;
872 GetExceptionInfo( &exceptionInfo );
873 MagickCore::Image* newImage =
874 EnhanceImage( image(), &exceptionInfo );
875 replaceImage( newImage );
876 throwException( exceptionInfo );
877 (void) DestroyExceptionInfo( &exceptionInfo );
878}
879
880// Equalize image (histogram equalization)
881void Magick::Image::equalize ( void )
882{
883 modifyImage();
884 EqualizeImage( image() );
885 throwImageException();
886}
887
888// Erase image to current "background color"
889void Magick::Image::erase ( void )
890{
891 modifyImage();
892 SetImageBackgroundColor( image() );
893 throwImageException();
894}
895
896// Extends image as defined by the geometry.
897//
898void Magick::Image::extent ( const Geometry &geometry_ )
899{
900 RectangleInfo extentInfo = geometry_;
901 modifyImage();
cristy8bf9e292010-02-21 17:48:01 +0000902 ExceptionInfo exceptionInfo;
903 GetExceptionInfo( &exceptionInfo );
cristy1ee42c42010-05-12 12:52:50 +0000904 MagickCore::Image* newImage =
905 ExtentImage ( image(), &extentInfo, &exceptionInfo );
906 replaceImage( newImage );
cristy8bf9e292010-02-21 17:48:01 +0000907 throwException( exceptionInfo );
908 (void) DestroyExceptionInfo( &exceptionInfo );
909}
910void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
911{
912 backgroundColor ( backgroundColor_ );
913 extent ( geometry_ );
914}
cristyff024b42010-02-21 22:55:09 +0000915void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
cristy8bf9e292010-02-21 17:48:01 +0000916{
917 image()->gravity = gravity_;
918 extent ( geometry_ );
919}
920void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
921{
922 image()->gravity = gravity_;
923 backgroundColor ( backgroundColor_ );
924 extent ( geometry_ );
cristy3ed852e2009-09-05 21:47:34 +0000925}
926
927// Flip image (reflect each scanline in the vertical direction)
928void Magick::Image::flip ( void )
929{
930 ExceptionInfo exceptionInfo;
931 GetExceptionInfo( &exceptionInfo );
932 MagickCore::Image* newImage =
933 FlipImage( image(), &exceptionInfo );
934 replaceImage( newImage );
935 throwException( exceptionInfo );
936 (void) DestroyExceptionInfo( &exceptionInfo );
937}
938
939// Flood-fill color across pixels that match the color of the
940// target pixel and are neighbors of the target pixel.
941// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000942void Magick::Image::floodFillColor( const ssize_t x_,
943 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000944 const Magick::Color &fillColor_ )
945{
946 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
947}
948void Magick::Image::floodFillColor( const Geometry &point_,
949 const Magick::Color &fillColor_ )
950{
951 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
952}
953
954// Flood-fill color across pixels starting at target-pixel and
955// stopping at pixels matching specified border color.
956// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000957void Magick::Image::floodFillColor( const ssize_t x_,
958 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000959 const Magick::Color &fillColor_,
960 const Magick::Color &borderColor_ )
961{
962 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
963 borderColor_ );
964}
965void Magick::Image::floodFillColor( const Geometry &point_,
966 const Magick::Color &fillColor_,
967 const Magick::Color &borderColor_ )
968{
969 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
970 borderColor_ );
971}
972
973// Floodfill pixels matching color (within fuzz factor) of target
cristy4c08aed2011-07-01 19:47:50 +0000974// pixel(x,y) with replacement alpha value using method.
cristy35ef8242010-06-03 16:24:13 +0000975void Magick::Image::floodFillOpacity( const ssize_t x_,
976 const ssize_t y_,
cristy4c08aed2011-07-01 19:47:50 +0000977 const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000978 const PaintMethod method_ )
979{
980 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +0000981 PixelInfo target;
982 GetPixelInfo(image(),&target);
cristy3ed852e2009-09-05 21:47:34 +0000983 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
984 target.red=pixel.red;
985 target.green=pixel.green;
986 target.blue=pixel.blue;
cristy4c08aed2011-07-01 19:47:50 +0000987 target.alpha=alpha_;
cristy3ed852e2009-09-05 21:47:34 +0000988 FloodfillPaintImage ( image(),
cristy3ed852e2009-09-05 21:47:34 +0000989 options()->drawInfo(), // const DrawInfo *draw_info
990 &target,
cristybb503372010-05-27 20:51:26 +0000991 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +0000992 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
993 throwImageException();
994}
995
996// Flood-fill texture across pixels that match the color of the
997// target pixel and are neighbors of the target pixel.
998// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000999void Magick::Image::floodFillTexture( const ssize_t x_,
1000 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001001 const Magick::Image &texture_ )
1002{
1003 modifyImage();
1004
1005 // Set drawing pattern
1006 options()->fillPattern(texture_.constImage());
1007
1008 // Get pixel view
1009 Pixels pixels(*this);
1010 // Fill image
cristy4c08aed2011-07-01 19:47:50 +00001011 Quantum *p = pixels.get(x_, y_, 1, 1 );
1012 PixelInfo target;
1013 GetPixelInfo(constImage(),&target);
1014 target.red=GetPixelRed(constImage(),p);
1015 target.green=GetPixelGreen(constImage(),p);
1016 target.blue=GetPixelBlue(constImage(),p);
cristy3ed852e2009-09-05 21:47:34 +00001017 if (p)
1018 FloodfillPaintImage ( image(), // Image *image
cristy3ed852e2009-09-05 21:47:34 +00001019 options()->drawInfo(), // const DrawInfo *draw_info
1020 &target, // const MagickPacket target
cristybb503372010-05-27 20:51:26 +00001021 static_cast<ssize_t>(x_), // const ssize_t x_offset
1022 static_cast<ssize_t>(y_), // const ssize_t y_offset
cristy3ed852e2009-09-05 21:47:34 +00001023 MagickFalse // const PaintMethod method
1024 );
1025
1026 throwImageException();
1027}
1028void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1029 const Magick::Image &texture_ )
1030{
1031 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1032}
1033
1034// Flood-fill texture across pixels starting at target-pixel and
1035// stopping at pixels matching specified border color.
1036// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +00001037void Magick::Image::floodFillTexture( const ssize_t x_,
1038 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001039 const Magick::Image &texture_,
1040 const Magick::Color &borderColor_ )
1041{
1042 modifyImage();
1043
1044 // Set drawing fill pattern
1045 options()->fillPattern(texture_.constImage());
1046
cristy4c08aed2011-07-01 19:47:50 +00001047 PixelInfo target;
1048 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001049 target.red=static_cast<PixelPacket>(borderColor_).red;
1050 target.green=static_cast<PixelPacket>(borderColor_).green;
1051 target.blue=static_cast<PixelPacket>(borderColor_).blue;
1052 FloodfillPaintImage ( image(),
cristy3ed852e2009-09-05 21:47:34 +00001053 options()->drawInfo(),
1054 &target,
cristybb503372010-05-27 20:51:26 +00001055 static_cast<ssize_t>(x_),
1056 static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +00001057 MagickTrue);
1058
1059 throwImageException();
1060}
1061void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1062 const Magick::Image &texture_,
1063 const Magick::Color &borderColor_ )
1064{
1065 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1066}
1067
1068// Flop image (reflect each scanline in the horizontal direction)
1069void Magick::Image::flop ( void )
1070{
1071 ExceptionInfo exceptionInfo;
1072 GetExceptionInfo( &exceptionInfo );
1073 MagickCore::Image* newImage =
1074 FlopImage( image(), &exceptionInfo );
1075 replaceImage( newImage );
1076 throwException( exceptionInfo );
1077 (void) DestroyExceptionInfo( &exceptionInfo );
1078}
1079
1080// Frame image
1081void Magick::Image::frame ( const Geometry &geometry_ )
1082{
1083 FrameInfo info;
1084
cristybb503372010-05-27 20:51:26 +00001085 info.x = static_cast<ssize_t>(geometry_.width());
1086 info.y = static_cast<ssize_t>(geometry_.height());
1087 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1088 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
cristy3ed852e2009-09-05 21:47:34 +00001089 info.outer_bevel = geometry_.xOff();
1090 info.inner_bevel = geometry_.yOff();
1091
1092 ExceptionInfo exceptionInfo;
1093 GetExceptionInfo( &exceptionInfo );
1094 MagickCore::Image* newImage =
1095 FrameImage( image(), &info, &exceptionInfo );
1096 replaceImage( newImage );
1097 throwException( exceptionInfo );
1098 (void) DestroyExceptionInfo( &exceptionInfo );
1099}
cristyeaedf062010-05-29 22:36:02 +00001100void Magick::Image::frame ( const size_t width_,
1101 const size_t height_,
cristyd99b0962010-05-29 23:14:26 +00001102 const ssize_t outerBevel_, const ssize_t innerBevel_ )
cristy3ed852e2009-09-05 21:47:34 +00001103{
1104 FrameInfo info;
cristybb503372010-05-27 20:51:26 +00001105 info.x = static_cast<ssize_t>(width_);
1106 info.y = static_cast<ssize_t>(height_);
1107 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1108 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1109 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1110 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
cristy3ed852e2009-09-05 21:47:34 +00001111
1112 ExceptionInfo exceptionInfo;
1113 GetExceptionInfo( &exceptionInfo );
1114 MagickCore::Image* newImage =
1115 FrameImage( image(), &info, &exceptionInfo );
1116 replaceImage( newImage );
1117 throwException( exceptionInfo );
1118 (void) DestroyExceptionInfo( &exceptionInfo );
1119}
1120
cristyc9550792009-11-13 20:05:42 +00001121// Fx image. Applies a mathematical expression to the image.
1122void Magick::Image::fx ( const std::string expression )
1123{
1124 ExceptionInfo exceptionInfo;
1125 GetExceptionInfo( &exceptionInfo );
1126 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001127 FxImage ( image(), expression.c_str(), &exceptionInfo );
cristyc9550792009-11-13 20:05:42 +00001128 replaceImage( newImage );
1129 throwException( exceptionInfo );
1130 (void) DestroyExceptionInfo( &exceptionInfo );
1131}
cristy3ed852e2009-09-05 21:47:34 +00001132void Magick::Image::fx ( const std::string expression,
1133 const Magick::ChannelType channel )
1134{
1135 ExceptionInfo exceptionInfo;
1136 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001137 PushPixelChannelMap( image(), channel );
cristy3ed852e2009-09-05 21:47:34 +00001138 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001139 FxImage ( image(), expression.c_str(), &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001140 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001141 replaceImage( newImage );
1142 throwException( exceptionInfo );
1143 (void) DestroyExceptionInfo( &exceptionInfo );
1144}
1145
1146// Gamma correct image
1147void Magick::Image::gamma ( const double gamma_ )
1148{
cristyb3e7c6c2011-07-24 01:43:55 +00001149 ExceptionInfo exceptionInfo;
1150 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001151 modifyImage();
cristyb3e7c6c2011-07-24 01:43:55 +00001152 GammaImage ( image(), gamma_, &exceptionInfo );
1153 throwException( exceptionInfo );
1154 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001155}
1156
1157void Magick::Image::gamma ( const double gammaRed_,
1158 const double gammaGreen_,
1159 const double gammaBlue_ )
1160{
1161 char gamma[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001162 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
cristy3ed852e2009-09-05 21:47:34 +00001163 gammaRed_, gammaGreen_, gammaBlue_);
1164
cristyb3e7c6c2011-07-24 01:43:55 +00001165 ExceptionInfo exceptionInfo;
1166 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001167 modifyImage();
cristyb3e7c6c2011-07-24 01:43:55 +00001168 GammaImage ( image(), atof(gamma), &exceptionInfo );
1169 throwException( exceptionInfo );
1170 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001171}
1172
1173// Gaussian blur image
1174// The number of neighbor pixels to be included in the convolution
1175// mask is specified by 'width_'. The standard deviation of the
1176// gaussian bell curve is specified by 'sigma_'.
1177void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1178{
1179 ExceptionInfo exceptionInfo;
1180 GetExceptionInfo( &exceptionInfo );
1181 MagickCore::Image* newImage =
1182 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1183 replaceImage( newImage );
1184 throwException( exceptionInfo );
1185 (void) DestroyExceptionInfo( &exceptionInfo );
1186}
1187
1188void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1189 const double width_,
1190 const double sigma_ )
1191{
1192 ExceptionInfo exceptionInfo;
1193 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001194 PushPixelChannelMap( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00001195 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +00001196 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001197 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001198 replaceImage( newImage );
1199 throwException( exceptionInfo );
1200 (void) DestroyExceptionInfo( &exceptionInfo );
1201}
1202
cristyb32b90a2009-09-07 21:45:48 +00001203// Apply a color lookup table (Hald CLUT) to the image.
1204void Magick::Image::haldClut ( const Image &clutImage_ )
1205{
1206 modifyImage();
1207 (void) HaldClutImage( image(), clutImage_.constImage() );
1208 throwImageException();
1209}
1210
cristy3ed852e2009-09-05 21:47:34 +00001211// Implode image
1212void Magick::Image::implode ( const double factor_ )
1213{
1214 ExceptionInfo exceptionInfo;
1215 GetExceptionInfo( &exceptionInfo );
1216 MagickCore::Image* newImage =
1217 ImplodeImage( image(), factor_, &exceptionInfo );
1218 replaceImage( newImage );
1219 throwException( exceptionInfo );
1220 (void) DestroyExceptionInfo( &exceptionInfo );
1221}
1222
cristy529fcc22009-11-14 18:15:08 +00001223// implements the inverse discrete Fourier transform (IFT) of the image either
1224// as a magnitude / phase or real / imaginary image pair.
1225void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1226{
1227 ExceptionInfo exceptionInfo;
1228 GetExceptionInfo( &exceptionInfo );
1229 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1230 phase_.constImage(), MagickTrue, &exceptionInfo);
1231 replaceImage( newImage );
1232 throwException( exceptionInfo );
1233 (void) DestroyExceptionInfo( &exceptionInfo );
1234}
1235void Magick::Image::inverseFourierTransform ( const Image &phase_,
1236 const bool magnitude_ )
1237{
1238 ExceptionInfo exceptionInfo;
1239 GetExceptionInfo( &exceptionInfo );
1240 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1241 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1242 &exceptionInfo);
1243 replaceImage( newImage );
1244 throwException( exceptionInfo );
1245 (void) DestroyExceptionInfo( &exceptionInfo );
1246}
1247
cristy3ed852e2009-09-05 21:47:34 +00001248// Level image. Adjust the levels of the image by scaling the colors
1249// falling between specified white and black points to the full
1250// available quantum range. The parameters provided represent the
1251// black, mid (gamma), and white points. The black point specifies
1252// the darkest color in the image. Colors darker than the black point
1253// are set to zero. Mid point (gamma) specifies a gamma correction to
1254// apply to the image. White point specifies the lightest color in the
1255// image. Colors brighter than the white point are set to the maximum
1256// quantum value. The black and white point have the valid range 0 to
1257// QuantumRange while gamma has a useful range of 0 to ten.
1258void Magick::Image::level ( const double black_point,
1259 const double white_point,
1260 const double gamma )
1261{
cristy01e9afd2011-08-10 17:38:41 +00001262 ExceptionInfo exceptionInfo;
1263 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001264 modifyImage();
cristy01e9afd2011-08-10 17:38:41 +00001265 (void) LevelImage( image(), black_point, white_point, gamma, &exceptionInfo );
1266 throwException( exceptionInfo );
1267 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001268}
1269
1270// Magnify image by integral size
1271void Magick::Image::magnify ( void )
1272{
1273 ExceptionInfo exceptionInfo;
1274 GetExceptionInfo( &exceptionInfo );
1275 MagickCore::Image* newImage =
1276 MagnifyImage( image(), &exceptionInfo );
1277 replaceImage( newImage );
1278 throwException( exceptionInfo );
1279 (void) DestroyExceptionInfo( &exceptionInfo );
1280}
1281
1282// Remap image colors with closest color from reference image
1283void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1284{
1285 modifyImage();
1286 options()->quantizeDither( dither_ );
1287 RemapImage ( options()->quantizeInfo(), image(),
1288 mapImage_.constImage());
1289 throwImageException();
1290}
cristy4c08aed2011-07-01 19:47:50 +00001291// Floodfill designated area with replacement alpha value
cristy3ed852e2009-09-05 21:47:34 +00001292void Magick::Image::matteFloodfill ( const Color &target_ ,
cristy4c08aed2011-07-01 19:47:50 +00001293 const unsigned int alpha_,
cristyd99b0962010-05-29 23:14:26 +00001294 const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001295 const Magick::PaintMethod method_ )
1296{
1297 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001298 PixelInfo target;
1299 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001300 target.red=static_cast<PixelPacket>(target_).red;
1301 target.green=static_cast<PixelPacket>(target_).green;
1302 target.blue=static_cast<PixelPacket>(target_).blue;
cristy4c08aed2011-07-01 19:47:50 +00001303 target.alpha=alpha_;
cristyed231572011-07-14 02:18:59 +00001304 PushPixelChannelMap( image(), AlphaChannel );
cristyd42d9952011-07-08 14:21:50 +00001305 FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
1306 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
cristyed231572011-07-14 02:18:59 +00001307 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001308 throwImageException();
1309}
1310
1311// Filter image by replacing each pixel component with the median
1312// color in a circular neighborhood
1313void Magick::Image::medianFilter ( const double radius_ )
1314{
1315 ExceptionInfo exceptionInfo;
1316 GetExceptionInfo( &exceptionInfo );
1317 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001318 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1319 radius_,&exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001320 replaceImage( newImage );
1321 throwException( exceptionInfo );
1322 (void) DestroyExceptionInfo( &exceptionInfo );
1323}
1324
1325// Reduce image by integral size
1326void Magick::Image::minify ( void )
1327{
1328 ExceptionInfo exceptionInfo;
1329 GetExceptionInfo( &exceptionInfo );
1330 MagickCore::Image* newImage =
1331 MinifyImage( image(), &exceptionInfo );
1332 replaceImage( newImage );
1333 throwException( exceptionInfo );
1334 (void) DestroyExceptionInfo( &exceptionInfo );
1335}
1336
1337// Modulate percent hue, saturation, and brightness of an image
1338void Magick::Image::modulate ( const double brightness_,
1339 const double saturation_,
1340 const double hue_ )
1341{
1342 char modulate[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001343 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
cristy3ed852e2009-09-05 21:47:34 +00001344 brightness_, saturation_, hue_);
1345
1346 modifyImage();
1347 ModulateImage( image(), modulate );
1348 throwImageException();
1349}
1350
1351// Motion blur image with specified blur factor
1352// The radius_ parameter specifies the radius of the Gaussian, in
1353// pixels, not counting the center pixel. The sigma_ parameter
1354// specifies the standard deviation of the Laplacian, in pixels.
1355// The angle_ parameter specifies the angle the object appears
1356// to be comming from (zero degrees is from the right).
1357void Magick::Image::motionBlur ( const double radius_,
1358 const double sigma_,
1359 const double angle_ )
1360{
1361 ExceptionInfo exceptionInfo;
1362 GetExceptionInfo( &exceptionInfo );
1363 MagickCore::Image* newImage =
1364 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1365 replaceImage( newImage );
1366 throwException( exceptionInfo );
1367 (void) DestroyExceptionInfo( &exceptionInfo );
1368}
1369
1370// Negate image. Set grayscale_ to true to effect grayscale values
1371// only
1372void Magick::Image::negate ( const bool grayscale_ )
1373{
cristyb3e7c6c2011-07-24 01:43:55 +00001374 ExceptionInfo exceptionInfo;
1375 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001376 modifyImage();
cristyb3e7c6c2011-07-24 01:43:55 +00001377 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse,
1378 &exceptionInfo );
1379 throwException( exceptionInfo );
1380 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001381}
1382
1383// Normalize image
1384void Magick::Image::normalize ( void )
1385{
1386 modifyImage();
1387 NormalizeImage ( image() );
1388 throwImageException();
1389}
1390
1391// Oilpaint image
1392void Magick::Image::oilPaint ( const double radius_ )
1393{
1394 ExceptionInfo exceptionInfo;
1395 GetExceptionInfo( &exceptionInfo );
1396 MagickCore::Image* newImage =
1397 OilPaintImage( image(), radius_, &exceptionInfo );
1398 replaceImage( newImage );
1399 throwException( exceptionInfo );
1400 (void) DestroyExceptionInfo( &exceptionInfo );
1401}
1402
cristy4c08aed2011-07-01 19:47:50 +00001403// Set or attenuate the alpha channel. If the image pixels are
1404// opaque then they are set to the specified alpha value, otherwise
1405// they are blended with the supplied alpha value. The value of
1406// alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1407// OpaqueAlpha and TransparentAlpha are available to specify
cristy3ed852e2009-09-05 21:47:34 +00001408// completely opaque or completely transparent, respectively.
cristy4c08aed2011-07-01 19:47:50 +00001409void Magick::Image::alpha ( const unsigned int alpha_ )
cristy3ed852e2009-09-05 21:47:34 +00001410{
1411 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001412 SetImageOpacity( image(), alpha_ );
cristy3ed852e2009-09-05 21:47:34 +00001413}
1414
1415// Change the color of an opaque pixel to the pen color.
1416void Magick::Image::opaque ( const Color &opaqueColor_,
1417 const Color &penColor_ )
1418{
1419 if ( !opaqueColor_.isValid() )
1420 {
1421 throwExceptionExplicit( OptionError,
1422 "Opaque color argument is invalid" );
1423 }
1424 if ( !penColor_.isValid() )
1425 {
1426 throwExceptionExplicit( OptionError,
1427 "Pen color argument is invalid" );
1428 }
1429
1430 modifyImage();
1431 std::string opaqueColor = opaqueColor_;
1432 std::string penColor = penColor_;
1433
cristy4c08aed2011-07-01 19:47:50 +00001434 PixelInfo opaque;
1435 PixelInfo pen;
cristy3ed852e2009-09-05 21:47:34 +00001436 (void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque,&image()->exception);
1437 (void) QueryMagickColor(std::string(penColor_).c_str(),&pen,&image()->exception);
1438 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse );
1439 throwImageException();
1440}
1441
1442// Ping is similar to read except only enough of the image is read to
1443// determine the image columns, rows, and filesize. Access the
1444// columns(), rows(), and fileSize() attributes after invoking ping.
1445// The image data is not valid after calling ping.
1446void Magick::Image::ping ( const std::string &imageSpec_ )
1447{
1448 options()->fileName( imageSpec_ );
1449 ExceptionInfo exceptionInfo;
1450 GetExceptionInfo( &exceptionInfo );
1451 MagickCore::Image* image =
1452 PingImage( imageInfo(), &exceptionInfo );
1453 replaceImage( image );
1454 throwException( exceptionInfo );
1455 (void) DestroyExceptionInfo( &exceptionInfo );
1456}
1457
1458// Ping is similar to read except only enough of the image is read
1459// to determine the image columns, rows, and filesize. Access the
1460// columns(), rows(), and fileSize() attributes after invoking
1461// ping. The image data is not valid after calling ping.
1462void Magick::Image::ping ( const Blob& blob_ )
1463{
1464 ExceptionInfo exceptionInfo;
1465 GetExceptionInfo( &exceptionInfo );
1466 MagickCore::Image* image =
1467 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1468 replaceImage( image );
1469 throwException( exceptionInfo );
1470 (void) DestroyExceptionInfo( &exceptionInfo );
1471}
1472
1473// Execute a named process module using an argc/argv syntax similar to
1474// that accepted by a C 'main' routine. An exception is thrown if the
1475// requested process module doesn't exist, fails to load, or fails during
1476// execution.
cristyd99b0962010-05-29 23:14:26 +00001477void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
cristy3ed852e2009-09-05 21:47:34 +00001478{
1479 modifyImage();
1480
cristyeaedf062010-05-29 22:36:02 +00001481 size_t status =
cristy3ed852e2009-09-05 21:47:34 +00001482 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1483 &image()->exception );
1484
1485 if (status == false)
1486 throwException( image()->exception );
1487}
1488
1489// Quantize colors in image using current quantization settings
1490// Set measureError_ to true in order to measure quantization error
1491void Magick::Image::quantize ( const bool measureError_ )
1492{
1493 modifyImage();
1494
1495 if (measureError_)
1496 options()->quantizeInfo()->measure_error=MagickTrue;
1497 else
1498 options()->quantizeInfo()->measure_error=MagickFalse;
1499
1500 QuantizeImage( options()->quantizeInfo(), image() );
1501
1502 throwImageException();
1503}
1504
1505// Apply an arithmetic or bitwise operator to the image pixel quantums.
1506void Magick::Image::quantumOperator ( const ChannelType channel_,
1507 const MagickEvaluateOperator operator_,
1508 double rvalue_)
1509{
1510 ExceptionInfo exceptionInfo;
1511 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001512 PushPixelChannelMap( image(), channel_ );
cristyd42d9952011-07-08 14:21:50 +00001513 EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
cristyed231572011-07-14 02:18:59 +00001514 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001515 throwException( exceptionInfo );
1516 (void) DestroyExceptionInfo( &exceptionInfo );
1517}
1518
cristyd99b0962010-05-29 23:14:26 +00001519void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00001520 const size_t columns_,
1521 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00001522 const ChannelType channel_,
1523 const MagickEvaluateOperator operator_,
1524 const double rvalue_)
1525{
1526 ExceptionInfo exceptionInfo;
1527 GetExceptionInfo( &exceptionInfo );
1528 RectangleInfo geometry;
1529 geometry.width = columns_;
1530 geometry.height = rows_;
1531 geometry.x = x_;
1532 geometry.y = y_;
1533 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1534 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001535 PushPixelChannelMap( image(), channel_);
cristyd42d9952011-07-08 14:21:50 +00001536 EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001537 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001538 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1539 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1540 crop_image = DestroyImageList(crop_image);
1541 throwException( exceptionInfo );
1542 (void) DestroyExceptionInfo( &exceptionInfo );
1543}
1544
1545// Raise image (lighten or darken the edges of an image to give a 3-D
1546// raised or lowered effect)
1547void Magick::Image::raise ( const Geometry &geometry_ ,
1548 const bool raisedFlag_ )
1549{
1550 RectangleInfo raiseInfo = geometry_;
1551 modifyImage();
1552 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse );
1553 throwImageException();
1554}
1555
1556
1557// Random threshold image.
1558//
1559// Changes the value of individual pixels based on the intensity
1560// of each pixel compared to a random threshold. The result is a
1561// low-contrast, two color image. The thresholds_ argument is a
1562// geometry containing LOWxHIGH thresholds. If the string
1563// contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1564// 3, or 4 will be performed instead. If a channel_ argument is
1565// specified then only the specified channel is altered. This is
1566// a very fast alternative to 'quantize' based dithering.
1567void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1568{
1569 randomThresholdChannel(thresholds_,DefaultChannels);
1570}
1571void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1572 const ChannelType channel_ )
1573{
1574 ExceptionInfo exceptionInfo;
1575 GetExceptionInfo( &exceptionInfo );
1576 modifyImage();
cristyed231572011-07-14 02:18:59 +00001577 PushPixelChannelMap( image(), channel_);
cristyf4ad9df2011-07-08 16:49:03 +00001578 (void) RandomThresholdImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00001579 static_cast<std::string>(thresholds_).c_str(),
1580 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001581 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001582 throwImageException();
1583 (void) DestroyExceptionInfo( &exceptionInfo );
1584}
1585
1586// Read image into current object
1587void Magick::Image::read ( const std::string &imageSpec_ )
1588{
1589 options()->fileName( imageSpec_ );
1590
1591 ExceptionInfo exceptionInfo;
1592 GetExceptionInfo( &exceptionInfo );
1593 MagickCore::Image* image =
1594 ReadImage( imageInfo(), &exceptionInfo );
1595
1596 // Ensure that multiple image frames were not read.
1597 if ( image && image->next )
1598 {
1599 // Destroy any extra image frames
1600 MagickCore::Image* next = image->next;
1601 image->next = 0;
1602 next->previous = 0;
1603 DestroyImageList( next );
1604
1605 }
1606 replaceImage( image );
1607 throwException( exceptionInfo );
1608 if ( image )
1609 throwException( image->exception );
1610 (void) DestroyExceptionInfo( &exceptionInfo );
1611}
1612
1613// Read image of specified size into current object
1614void Magick::Image::read ( const Geometry &size_,
1615 const std::string &imageSpec_ )
1616{
1617 size( size_ );
1618 read( imageSpec_ );
1619}
1620
1621// Read image from in-memory BLOB
1622void Magick::Image::read ( const Blob &blob_ )
1623{
1624 ExceptionInfo exceptionInfo;
1625 GetExceptionInfo( &exceptionInfo );
1626 MagickCore::Image* image =
1627 BlobToImage( imageInfo(),
1628 static_cast<const void *>(blob_.data()),
1629 blob_.length(), &exceptionInfo );
1630 replaceImage( image );
1631 throwException( exceptionInfo );
1632 if ( image )
1633 throwException( image->exception );
1634 (void) DestroyExceptionInfo( &exceptionInfo );
1635}
1636
1637// Read image of specified size from in-memory BLOB
1638void Magick::Image::read ( const Blob &blob_,
1639 const Geometry &size_ )
1640{
1641 // Set image size
1642 size( size_ );
1643 // Read from Blob
1644 read( blob_ );
1645}
1646
1647// Read image of specified size and depth from in-memory BLOB
1648void Magick::Image::read ( const Blob &blob_,
1649 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001650 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00001651{
1652 // Set image size
1653 size( size_ );
1654 // Set image depth
1655 depth( depth_ );
1656 // Read from Blob
1657 read( blob_ );
1658}
1659
1660// Read image of specified size, depth, and format from in-memory BLOB
1661void Magick::Image::read ( const Blob &blob_,
1662 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001663 const size_t depth_,
cristy3ed852e2009-09-05 21:47:34 +00001664 const std::string &magick_ )
1665{
1666 // Set image size
1667 size( size_ );
1668 // Set image depth
1669 depth( depth_ );
1670 // Set image magick
1671 magick( magick_ );
1672 // Set explicit image format
1673 fileName( magick_ + ':');
1674 // Read from Blob
1675 read( blob_ );
1676}
1677
1678// Read image of specified size, and format from in-memory BLOB
1679void Magick::Image::read ( const Blob &blob_,
1680 const Geometry &size_,
1681 const std::string &magick_ )
1682{
1683 // Set image size
1684 size( size_ );
1685 // Set image magick
1686 magick( magick_ );
1687 // Set explicit image format
1688 fileName( magick_ + ':');
1689 // Read from Blob
1690 read( blob_ );
1691}
1692
1693// Read image based on raw pixels in memory (ConstituteImage)
cristyeaedf062010-05-29 22:36:02 +00001694void Magick::Image::read ( const size_t width_,
1695 const size_t height_,
cristy3ed852e2009-09-05 21:47:34 +00001696 const std::string &map_,
1697 const StorageType type_,
1698 const void *pixels_ )
1699{
1700 ExceptionInfo exceptionInfo;
1701 GetExceptionInfo( &exceptionInfo );
1702 MagickCore::Image* image =
1703 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1704 &exceptionInfo );
1705 replaceImage( image );
1706 throwException( exceptionInfo );
1707 if ( image )
1708 throwException( image->exception );
1709 (void) DestroyExceptionInfo( &exceptionInfo );
1710}
1711
cristy3ed852e2009-09-05 21:47:34 +00001712// Reduce noise in image
1713void Magick::Image::reduceNoise ( const double order_ )
1714{
1715 ExceptionInfo exceptionInfo;
1716 GetExceptionInfo( &exceptionInfo );
1717 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001718 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1719 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001720 replaceImage( newImage );
1721 throwException( exceptionInfo );
1722 (void) DestroyExceptionInfo( &exceptionInfo );
1723}
1724
1725// Resize image
1726void Magick::Image::resize( const Geometry &geometry_ )
1727{
1728 // Calculate new size. This code should be supported using binary arguments
1729 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00001730 ssize_t x = 0;
1731 ssize_t y = 0;
1732 size_t width = columns();
1733 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001734
1735 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1736 &x, &y,
1737 &width, &height );
1738
1739 ExceptionInfo exceptionInfo;
1740 GetExceptionInfo( &exceptionInfo );
1741 MagickCore::Image* newImage =
1742 ResizeImage( image(),
1743 width,
1744 height,
1745 image()->filter,
1746 1.0,
1747 &exceptionInfo);
1748 replaceImage( newImage );
1749 throwException( exceptionInfo );
1750 (void) DestroyExceptionInfo( &exceptionInfo );
1751}
1752
1753// Roll image
1754void Magick::Image::roll ( const Geometry &roll_ )
1755{
cristybb503372010-05-27 20:51:26 +00001756 ssize_t xOff = roll_.xOff();
cristy3ed852e2009-09-05 21:47:34 +00001757 if ( roll_.xNegative() )
1758 xOff = 0 - xOff;
cristybb503372010-05-27 20:51:26 +00001759 ssize_t yOff = roll_.yOff();
cristy3ed852e2009-09-05 21:47:34 +00001760 if ( roll_.yNegative() )
1761 yOff = 0 - yOff;
1762
1763 ExceptionInfo exceptionInfo;
1764 GetExceptionInfo( &exceptionInfo );
1765 MagickCore::Image* newImage =
1766 RollImage( image(), xOff, yOff, &exceptionInfo );
1767 replaceImage( newImage );
1768 throwException( exceptionInfo );
1769 (void) DestroyExceptionInfo( &exceptionInfo );
1770}
cristyeaedf062010-05-29 22:36:02 +00001771void Magick::Image::roll ( const size_t columns_,
1772 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00001773{
1774 ExceptionInfo exceptionInfo;
1775 GetExceptionInfo( &exceptionInfo );
1776 MagickCore::Image* newImage =
1777 RollImage( image(),
cristybb503372010-05-27 20:51:26 +00001778 static_cast<ssize_t>(columns_),
1779 static_cast<ssize_t>(rows_), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001780 replaceImage( newImage );
1781 throwException( exceptionInfo );
1782 (void) DestroyExceptionInfo( &exceptionInfo );
1783}
1784
1785// Rotate image
1786void Magick::Image::rotate ( const double degrees_ )
1787{
1788 ExceptionInfo exceptionInfo;
1789 GetExceptionInfo( &exceptionInfo );
1790 MagickCore::Image* newImage =
1791 RotateImage( image(), degrees_, &exceptionInfo);
1792 replaceImage( newImage );
1793 throwException( exceptionInfo );
1794 (void) DestroyExceptionInfo( &exceptionInfo );
1795}
1796
1797// Sample image
1798void Magick::Image::sample ( const Geometry &geometry_ )
1799{
cristybb503372010-05-27 20:51:26 +00001800 ssize_t x = 0;
1801 ssize_t y = 0;
1802 size_t width = columns();
1803 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001804
1805 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1806 &x, &y,
1807 &width, &height );
1808
1809 ExceptionInfo exceptionInfo;
1810 GetExceptionInfo( &exceptionInfo );
1811 MagickCore::Image* newImage =
1812 SampleImage( image(), width, height, &exceptionInfo );
1813 replaceImage( newImage );
1814 throwException( exceptionInfo );
1815 (void) DestroyExceptionInfo( &exceptionInfo );
1816}
1817
1818// Scale image
1819void Magick::Image::scale ( const Geometry &geometry_ )
1820{
cristybb503372010-05-27 20:51:26 +00001821 ssize_t x = 0;
1822 ssize_t y = 0;
1823 size_t width = columns();
1824 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001825
1826 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1827 &x, &y,
1828 &width, &height );
1829
1830 ExceptionInfo exceptionInfo;
1831 GetExceptionInfo( &exceptionInfo );
1832 MagickCore::Image* newImage =
1833 ScaleImage( image(), width, height, &exceptionInfo );
1834 replaceImage( newImage );
1835 throwException( exceptionInfo );
1836 (void) DestroyExceptionInfo( &exceptionInfo );
1837}
1838
1839// Segment (coalesce similar image components) by analyzing the
1840// histograms of the color components and identifying units that are
1841// homogeneous with the fuzzy c-means technique.
1842void Magick::Image::segment ( const double clusterThreshold_,
1843 const double smoothingThreshold_ )
1844{
1845 modifyImage();
1846 SegmentImage ( image(),
1847 options()->quantizeColorSpace(),
1848 (MagickBooleanType) options()->verbose(),
1849 clusterThreshold_,
1850 smoothingThreshold_ );
1851 throwImageException();
1852 SyncImage( image() );
1853 throwImageException();
1854}
1855
1856// Shade image using distant light source
1857void Magick::Image::shade ( const double azimuth_,
1858 const double elevation_,
1859 const bool colorShading_ )
1860{
1861 ExceptionInfo exceptionInfo;
1862 GetExceptionInfo( &exceptionInfo );
1863 MagickCore::Image* newImage =
1864 ShadeImage( image(),
1865 colorShading_ == true ? MagickTrue : MagickFalse,
1866 azimuth_,
1867 elevation_,
1868 &exceptionInfo);
1869 replaceImage( newImage );
1870 throwException( exceptionInfo );
1871 (void) DestroyExceptionInfo( &exceptionInfo );
1872}
1873
1874// Sharpen pixels in image
1875void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1876{
1877 ExceptionInfo exceptionInfo;
1878 GetExceptionInfo( &exceptionInfo );
1879 MagickCore::Image* newImage =
1880 SharpenImage( image(),
1881 radius_,
1882 sigma_,
1883 &exceptionInfo );
1884 replaceImage( newImage );
1885 throwException( exceptionInfo );
1886 (void) DestroyExceptionInfo( &exceptionInfo );
1887}
1888
1889void Magick::Image::sharpenChannel ( const ChannelType channel_,
1890 const double radius_, const double sigma_ )
1891{
1892 ExceptionInfo exceptionInfo;
1893 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001894 PushPixelChannelMap( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00001895 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +00001896 SharpenImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00001897 radius_,
1898 sigma_,
1899 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001900 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001901 replaceImage( newImage );
1902 throwException( exceptionInfo );
1903 (void) DestroyExceptionInfo( &exceptionInfo );
1904}
1905
1906// Shave pixels from image edges.
1907void Magick::Image::shave ( const Geometry &geometry_ )
1908{
1909 RectangleInfo shaveInfo = geometry_;
1910 ExceptionInfo exceptionInfo;
1911 GetExceptionInfo( &exceptionInfo );
1912 MagickCore::Image* newImage =
1913 ShaveImage( image(),
1914 &shaveInfo,
1915 &exceptionInfo);
1916 replaceImage( newImage );
1917 throwException( exceptionInfo );
1918 (void) DestroyExceptionInfo( &exceptionInfo );
1919}
1920
1921// Shear image
1922void Magick::Image::shear ( const double xShearAngle_,
1923 const double yShearAngle_ )
1924{
1925 ExceptionInfo exceptionInfo;
1926 GetExceptionInfo( &exceptionInfo );
1927 MagickCore::Image* newImage =
1928 ShearImage( image(),
1929 xShearAngle_,
1930 yShearAngle_,
1931 &exceptionInfo );
1932 replaceImage( newImage );
1933 throwException( exceptionInfo );
1934 (void) DestroyExceptionInfo( &exceptionInfo );
1935}
1936
1937// Contrast image
cristyeaedf062010-05-29 22:36:02 +00001938void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
cristy3ed852e2009-09-05 21:47:34 +00001939{
1940 modifyImage();
cristy9ee60942011-07-06 14:54:38 +00001941 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint );
cristy3ed852e2009-09-05 21:47:34 +00001942 throwImageException();
1943}
1944
1945// Solarize image (similar to effect seen when exposing a photographic
1946// film to light during the development process)
1947void Magick::Image::solarize ( const double factor_ )
1948{
1949 modifyImage();
1950 SolarizeImage ( image(), factor_ );
1951 throwImageException();
1952}
1953
1954// Sparse color image, given a set of coordinates, interpolates the colors
1955// found at those coordinates, across the whole image, using various methods.
1956//
1957void Magick::Image::sparseColor ( const ChannelType channel,
1958 const SparseColorMethod method,
cristybb503372010-05-27 20:51:26 +00001959 const size_t number_arguments,
cristy3ed852e2009-09-05 21:47:34 +00001960 const double *arguments )
1961{
1962 ExceptionInfo exceptionInfo;
1963 GetExceptionInfo( &exceptionInfo );
cristy3884f692011-07-08 18:00:18 +00001964
cristyed231572011-07-14 02:18:59 +00001965 PushPixelChannelMap( image(), channel );
cristy3884f692011-07-08 18:00:18 +00001966 MagickCore::Image* newImage = SparseColorImage ( image(), method,
cristy3ed852e2009-09-05 21:47:34 +00001967 number_arguments, arguments, &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001968 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001969 replaceImage( newImage );
1970 throwException( exceptionInfo );
1971 (void) DestroyExceptionInfo( &exceptionInfo );
1972}
1973
1974// Spread pixels randomly within image by specified ammount
cristyeaedf062010-05-29 22:36:02 +00001975void Magick::Image::spread ( const size_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +00001976{
1977 ExceptionInfo exceptionInfo;
1978 GetExceptionInfo( &exceptionInfo );
1979 MagickCore::Image* newImage =
1980 SpreadImage( image(),
1981 amount_,
1982 &exceptionInfo );
1983 replaceImage( newImage );
1984 throwException( exceptionInfo );
1985 (void) DestroyExceptionInfo( &exceptionInfo );
1986}
1987
1988// Add a digital watermark to the image (based on second image)
1989void Magick::Image::stegano ( const Image &watermark_ )
1990{
1991 ExceptionInfo exceptionInfo;
1992 GetExceptionInfo( &exceptionInfo );
1993 MagickCore::Image* newImage =
1994 SteganoImage( image(),
1995 watermark_.constImage(),
1996 &exceptionInfo);
1997 replaceImage( newImage );
1998 throwException( exceptionInfo );
1999 (void) DestroyExceptionInfo( &exceptionInfo );
2000}
2001
2002// Stereo image (left image is current image)
2003void Magick::Image::stereo ( const Image &rightImage_ )
2004{
2005 ExceptionInfo exceptionInfo;
2006 GetExceptionInfo( &exceptionInfo );
2007 MagickCore::Image* newImage =
2008 StereoImage( image(),
2009 rightImage_.constImage(),
2010 &exceptionInfo);
2011 replaceImage( newImage );
2012 throwException( exceptionInfo );
2013 (void) DestroyExceptionInfo( &exceptionInfo );
2014}
2015
2016// Swirl image
2017void Magick::Image::swirl ( const double degrees_ )
2018{
2019 ExceptionInfo exceptionInfo;
2020 GetExceptionInfo( &exceptionInfo );
2021 MagickCore::Image* newImage =
2022 SwirlImage( image(), degrees_,
2023 &exceptionInfo);
2024 replaceImage( newImage );
2025 throwException( exceptionInfo );
2026 (void) DestroyExceptionInfo( &exceptionInfo );
2027}
2028
2029// Texture image
2030void Magick::Image::texture ( const Image &texture_ )
2031{
2032 modifyImage();
2033 TextureImage( image(), texture_.constImage() );
2034 throwImageException();
2035}
2036
2037// Threshold image
2038void Magick::Image::threshold ( const double threshold_ )
2039{
2040 modifyImage();
2041 BilevelImage( image(), threshold_ );
2042 throwImageException();
2043}
2044
2045// Transform image based on image geometry only
2046void Magick::Image::transform ( const Geometry &imageGeometry_ )
2047{
2048 modifyImage();
2049 TransformImage ( &(image()), 0,
2050 std::string(imageGeometry_).c_str() );
2051 throwImageException();
2052}
2053// Transform image based on image and crop geometries
2054void Magick::Image::transform ( const Geometry &imageGeometry_,
2055 const Geometry &cropGeometry_ )
2056{
2057 modifyImage();
2058 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2059 std::string(imageGeometry_).c_str() );
2060 throwImageException();
2061}
2062
2063// Add matte image to image, setting pixels matching color to transparent
2064void Magick::Image::transparent ( const Color &color_ )
2065{
2066 if ( !color_.isValid() )
2067 {
2068 throwExceptionExplicit( OptionError,
2069 "Color argument is invalid" );
2070 }
2071
2072 std::string color = color_;
2073
cristy4c08aed2011-07-01 19:47:50 +00002074 PixelInfo target;
cristy3ed852e2009-09-05 21:47:34 +00002075 (void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
2076 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00002077 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse );
cristy3ed852e2009-09-05 21:47:34 +00002078 throwImageException();
2079}
2080
2081// Add matte image to image, setting pixels matching color to transparent
2082void Magick::Image::transparentChroma(const Color &colorLow_,
2083 const Color &colorHigh_)
2084{
2085 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2086 {
2087 throwExceptionExplicit( OptionError,
2088 "Color argument is invalid" );
2089 }
2090
2091 std::string colorLow = colorLow_;
2092 std::string colorHigh = colorHigh_;
2093
cristy4c08aed2011-07-01 19:47:50 +00002094 PixelInfo targetLow;
2095 PixelInfo targetHigh;
cristy3ed852e2009-09-05 21:47:34 +00002096 (void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
2097 &image()->exception);
2098 (void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
2099 &image()->exception);
2100 modifyImage();
2101 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
cristy4c08aed2011-07-01 19:47:50 +00002102 TransparentAlpha, MagickFalse );
cristy3ed852e2009-09-05 21:47:34 +00002103 throwImageException();
2104}
2105
2106
2107// Trim edges that are the background color from the image
2108void Magick::Image::trim ( void )
2109{
2110 ExceptionInfo exceptionInfo;
2111 GetExceptionInfo( &exceptionInfo );
2112 MagickCore::Image* newImage =
2113 TrimImage( image(), &exceptionInfo);
2114 replaceImage( newImage );
2115 throwException( exceptionInfo );
2116 (void) DestroyExceptionInfo( &exceptionInfo );
2117}
2118
2119// Replace image with a sharpened version of the original image
2120// using the unsharp mask algorithm.
2121// radius_
2122// the radius of the Gaussian, in pixels, not counting the
2123// center pixel.
2124// sigma_
2125// the standard deviation of the Gaussian, in pixels.
2126// amount_
2127// the percentage of the difference between the original and
2128// the blur image that is added back into the original.
2129// threshold_
2130// the threshold in pixels needed to apply the diffence amount.
2131void Magick::Image::unsharpmask ( const double radius_,
2132 const double sigma_,
2133 const double amount_,
2134 const double threshold_ )
2135{
2136 ExceptionInfo exceptionInfo;
2137 GetExceptionInfo( &exceptionInfo );
2138 MagickCore::Image* newImage =
2139 UnsharpMaskImage( image(),
2140 radius_,
2141 sigma_,
2142 amount_,
2143 threshold_,
2144 &exceptionInfo );
2145 replaceImage( newImage );
2146 throwException( exceptionInfo );
2147 (void) DestroyExceptionInfo( &exceptionInfo );
2148}
2149
2150void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2151 const double radius_,
2152 const double sigma_,
2153 const double amount_,
2154 const double threshold_ )
2155{
2156 ExceptionInfo exceptionInfo;
2157 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00002158 PushPixelChannelMap( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00002159 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +00002160 UnsharpMaskImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00002161 radius_,
2162 sigma_,
2163 amount_,
2164 threshold_,
2165 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00002166 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00002167 replaceImage( newImage );
2168 throwException( exceptionInfo );
2169 (void) DestroyExceptionInfo( &exceptionInfo );
2170}
2171
2172// Map image pixels to a sine wave
2173void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2174{
2175 ExceptionInfo exceptionInfo;
2176 GetExceptionInfo( &exceptionInfo );
2177 MagickCore::Image* newImage =
2178 WaveImage( image(),
2179 amplitude_,
2180 wavelength_,
2181 &exceptionInfo);
2182 replaceImage( newImage );
2183 throwException( exceptionInfo );
2184 (void) DestroyExceptionInfo( &exceptionInfo );
2185}
2186
2187// Write image to file
2188void Magick::Image::write( const std::string &imageSpec_ )
2189{
2190 modifyImage();
2191 fileName( imageSpec_ );
2192 WriteImage( imageInfo(), image() );
2193 throwImageException();
2194}
2195
2196// Write image to in-memory BLOB
2197void Magick::Image::write ( Blob *blob_ )
2198{
2199 modifyImage();
2200 size_t length = 2048; // Efficient size for small images
2201 ExceptionInfo exceptionInfo;
2202 GetExceptionInfo( &exceptionInfo );
2203 void* data = ImageToBlob( imageInfo(),
2204 image(),
2205 &length,
2206 &exceptionInfo);
2207 throwException( exceptionInfo );
2208 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2209 throwImageException();
2210 (void) DestroyExceptionInfo( &exceptionInfo );
2211}
2212void Magick::Image::write ( Blob *blob_,
2213 const std::string &magick_ )
2214{
2215 modifyImage();
2216 magick(magick_);
2217 size_t length = 2048; // Efficient size for small images
2218 ExceptionInfo exceptionInfo;
2219 GetExceptionInfo( &exceptionInfo );
2220 void* data = ImageToBlob( imageInfo(),
2221 image(),
2222 &length,
2223 &exceptionInfo);
2224 throwException( exceptionInfo );
2225 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2226 throwImageException();
2227 (void) DestroyExceptionInfo( &exceptionInfo );
2228}
2229void Magick::Image::write ( Blob *blob_,
2230 const std::string &magick_,
cristyeaedf062010-05-29 22:36:02 +00002231 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002232{
2233 modifyImage();
2234 magick(magick_);
2235 depth(depth_);
2236 size_t length = 2048; // Efficient size for small images
2237 ExceptionInfo exceptionInfo;
2238 GetExceptionInfo( &exceptionInfo );
2239 void* data = ImageToBlob( imageInfo(),
2240 image(),
2241 &length,
2242 &exceptionInfo);
2243 throwException( exceptionInfo );
2244 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2245 throwImageException();
2246 (void) DestroyExceptionInfo( &exceptionInfo );
2247}
2248
2249// Write image to an array of pixels with storage type specified
2250// by user (ExportImagePixels), e.g.
2251// image.write( 0, 0, 640, 1, "RGB", 0, pixels );
cristyd99b0962010-05-29 23:14:26 +00002252void Magick::Image::write ( const ssize_t x_,
2253 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00002254 const size_t columns_,
2255 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00002256 const std::string &map_,
2257 const StorageType type_,
2258 void *pixels_ )
2259{
2260 ExceptionInfo exceptionInfo;
2261 GetExceptionInfo( &exceptionInfo );
2262 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2263 pixels_,
2264 &exceptionInfo);
2265 throwException( exceptionInfo );
2266 (void) DestroyExceptionInfo( &exceptionInfo );
2267}
2268
2269// Zoom image
2270void Magick::Image::zoom( const Geometry &geometry_ )
2271{
2272 // Calculate new size. This code should be supported using binary arguments
2273 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00002274 ssize_t x = 0;
2275 ssize_t y = 0;
2276 size_t width = columns();
2277 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00002278
2279 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2280 &x, &y,
2281 &width, &height );
2282
2283 ExceptionInfo exceptionInfo;
2284 GetExceptionInfo( &exceptionInfo );
2285 MagickCore::Image* newImage =
cristy391f1ce2010-09-09 17:23:28 +00002286 ResizeImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00002287 width,
2288 height,
cristy391f1ce2010-09-09 17:23:28 +00002289 image()->filter,
2290 image()->blur,
cristy3ed852e2009-09-05 21:47:34 +00002291 &exceptionInfo);
2292 replaceImage( newImage );
2293 throwException( exceptionInfo );
2294 (void) DestroyExceptionInfo( &exceptionInfo );
2295}
2296
2297/*
2298 * Methods for setting image attributes
2299 *
2300 */
2301
2302// Join images into a single multi-image file
2303void Magick::Image::adjoin ( const bool flag_ )
2304{
2305 modifyImage();
2306 options()->adjoin( flag_ );
2307}
2308bool Magick::Image::adjoin ( void ) const
2309{
2310 return constOptions()->adjoin();
2311}
2312
2313// Remove pixel aliasing
2314void Magick::Image::antiAlias( const bool flag_ )
2315{
2316 modifyImage();
cristyeaedf062010-05-29 22:36:02 +00002317 options()->antiAlias( static_cast<size_t>(flag_) );
cristy3ed852e2009-09-05 21:47:34 +00002318}
2319bool Magick::Image::antiAlias( void )
2320{
2321 return static_cast<bool>( options()->antiAlias( ) );
2322}
2323
2324// Animation inter-frame delay
cristyeaedf062010-05-29 22:36:02 +00002325void Magick::Image::animationDelay ( const size_t delay_ )
cristy3ed852e2009-09-05 21:47:34 +00002326{
2327 modifyImage();
2328 image()->delay = delay_;
2329}
cristyeaedf062010-05-29 22:36:02 +00002330size_t Magick::Image::animationDelay ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002331{
2332 return constImage()->delay;
2333}
2334
2335// Number of iterations to play animation
cristyeaedf062010-05-29 22:36:02 +00002336void Magick::Image::animationIterations ( const size_t iterations_ )
cristy3ed852e2009-09-05 21:47:34 +00002337{
2338 modifyImage();
2339 image()->iterations = iterations_;
2340}
cristyeaedf062010-05-29 22:36:02 +00002341size_t Magick::Image::animationIterations ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002342{
2343 return constImage()->iterations;
2344}
2345
2346// Access/Update a named image attribute
2347void Magick::Image::attribute ( const std::string name_,
2348 const std::string value_ )
2349{
2350 modifyImage();
2351 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2352}
2353std::string Magick::Image::attribute ( const std::string name_ )
2354{
2355 const char *value = GetImageProperty( constImage(), name_.c_str() );
2356
2357 if ( value )
2358 return std::string( value );
2359
2360 return std::string(); // Intentionally no exception
2361}
2362
2363// Background color
cristy391f1ce2010-09-09 17:23:28 +00002364void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002365{
2366 modifyImage();
2367
cristy391f1ce2010-09-09 17:23:28 +00002368 if ( backgroundColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002369 {
cristy391f1ce2010-09-09 17:23:28 +00002370 image()->background_color = backgroundColor_;
cristy3ed852e2009-09-05 21:47:34 +00002371 }
2372 else
2373 {
cristy391f1ce2010-09-09 17:23:28 +00002374 image()->background_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002375 }
2376
cristy391f1ce2010-09-09 17:23:28 +00002377 options()->backgroundColor( backgroundColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002378}
2379Magick::Color Magick::Image::backgroundColor ( void ) const
2380{
2381 return constOptions()->backgroundColor( );
2382}
2383
2384// Background fill texture
2385void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2386{
2387 modifyImage();
2388 options()->backgroundTexture( backgroundTexture_ );
2389}
2390std::string Magick::Image::backgroundTexture ( void ) const
2391{
2392 return constOptions()->backgroundTexture( );
2393}
2394
2395// Original image columns
cristyeaedf062010-05-29 22:36:02 +00002396size_t Magick::Image::baseColumns ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002397{
2398 return constImage()->magick_columns;
2399}
2400
2401// Original image name
2402std::string Magick::Image::baseFilename ( void ) const
2403{
2404 return std::string(constImage()->magick_filename);
2405}
2406
2407// Original image rows
cristyeaedf062010-05-29 22:36:02 +00002408size_t Magick::Image::baseRows ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002409{
2410 return constImage()->magick_rows;
2411}
2412
2413// Border color
cristy391f1ce2010-09-09 17:23:28 +00002414void Magick::Image::borderColor ( const Color &borderColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002415{
2416 modifyImage();
2417
cristy391f1ce2010-09-09 17:23:28 +00002418 if ( borderColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002419 {
cristy391f1ce2010-09-09 17:23:28 +00002420 image()->border_color = borderColor_;
cristy3ed852e2009-09-05 21:47:34 +00002421 }
2422 else
2423 {
cristy391f1ce2010-09-09 17:23:28 +00002424 image()->border_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002425 }
2426
cristy391f1ce2010-09-09 17:23:28 +00002427 options()->borderColor( borderColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002428}
2429Magick::Color Magick::Image::borderColor ( void ) const
2430{
2431 return constOptions()->borderColor( );
2432}
2433
2434// Return smallest bounding box enclosing non-border pixels. The
2435// current fuzz value is used when discriminating between pixels.
2436// This is the crop bounding box used by crop(Geometry(0,0));
2437Magick::Geometry Magick::Image::boundingBox ( void ) const
2438{
2439 ExceptionInfo exceptionInfo;
2440 GetExceptionInfo( &exceptionInfo );
2441 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2442 throwException( exceptionInfo );
2443 (void) DestroyExceptionInfo( &exceptionInfo );
2444 return Geometry( bbox );
2445}
2446
2447// Text bounding-box base color
2448void Magick::Image::boxColor ( const Color &boxColor_ )
2449{
2450 modifyImage();
2451 options()->boxColor( boxColor_ );
2452}
2453Magick::Color Magick::Image::boxColor ( void ) const
2454{
2455 return constOptions()->boxColor( );
2456}
2457
2458// Pixel cache threshold. Once this threshold is exceeded, all
2459// subsequent pixels cache operations are to/from disk.
2460// This setting is shared by all Image objects.
2461/* static */
cristyeaedf062010-05-29 22:36:02 +00002462void Magick::Image::cacheThreshold ( const size_t threshold_ )
cristy3ed852e2009-09-05 21:47:34 +00002463{
2464 SetMagickResourceLimit( MemoryResource, threshold_ );
2465}
2466
2467void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2468{
2469 modifyImage();
2470 image()->chromaticity.blue_primary.x = x_;
2471 image()->chromaticity.blue_primary.y = y_;
2472}
2473void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2474{
2475 *x_ = constImage()->chromaticity.blue_primary.x;
2476 *y_ = constImage()->chromaticity.blue_primary.y;
2477}
2478
2479void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2480{
2481 modifyImage();
2482 image()->chromaticity.green_primary.x = x_;
2483 image()->chromaticity.green_primary.y = y_;
2484}
2485void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2486{
2487 *x_ = constImage()->chromaticity.green_primary.x;
2488 *y_ = constImage()->chromaticity.green_primary.y;
2489}
2490
2491void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2492{
2493 modifyImage();
2494 image()->chromaticity.red_primary.x = x_;
2495 image()->chromaticity.red_primary.y = y_;
2496}
2497void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2498{
2499 *x_ = constImage()->chromaticity.red_primary.x;
2500 *y_ = constImage()->chromaticity.red_primary.y;
2501}
2502
2503void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2504{
2505 modifyImage();
2506 image()->chromaticity.white_point.x = x_;
2507 image()->chromaticity.white_point.y = y_;
2508}
2509void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2510{
2511 *x_ = constImage()->chromaticity.white_point.x;
2512 *y_ = constImage()->chromaticity.white_point.y;
2513}
2514
2515// Set image storage class
2516void Magick::Image::classType ( const ClassType class_ )
2517{
2518 if ( classType() == PseudoClass && class_ == DirectClass )
2519 {
2520 // Use SyncImage to synchronize the DirectClass pixels with the
2521 // color map and then set to DirectClass type.
2522 modifyImage();
2523 SyncImage( image() );
2524 image()->colormap = (PixelPacket *)
2525 RelinquishMagickMemory( image()->colormap );
2526 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2527 return;
2528 }
2529
2530 if ( classType() == DirectClass && class_ == PseudoClass )
2531 {
2532 // Quantize to create PseudoClass color map
2533 modifyImage();
cristye6bbc092010-05-12 17:00:47 +00002534 quantizeColors(MaxColormapSize);
cristy3ed852e2009-09-05 21:47:34 +00002535 quantize();
2536 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2537 }
2538}
2539
2540// Associate a clip mask with the image. The clip mask must be the
2541// same dimensions as the image. Pass an invalid image to unset an
2542// existing clip mask.
2543void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2544{
2545 modifyImage();
2546
2547 if( clipMask_.isValid() )
2548 {
2549 // Set clip mask
2550 SetImageClipMask( image(), clipMask_.constImage() );
2551 }
2552 else
2553 {
2554 // Unset existing clip mask
2555 SetImageClipMask( image(), 0 );
2556 }
2557}
2558Magick::Image Magick::Image::clipMask ( void ) const
2559{
2560 ExceptionInfo exceptionInfo;
2561 GetExceptionInfo( &exceptionInfo );
2562 MagickCore::Image* image =
2563 GetImageClipMask( constImage(), &exceptionInfo );
2564 throwException( exceptionInfo );
2565 (void) DestroyExceptionInfo( &exceptionInfo );
2566 return Magick::Image( image );
2567}
2568
2569void Magick::Image::colorFuzz ( const double fuzz_ )
2570{
2571 modifyImage();
2572 image()->fuzz = fuzz_;
2573 options()->colorFuzz( fuzz_ );
2574}
2575double Magick::Image::colorFuzz ( void ) const
2576{
2577 return constOptions()->colorFuzz( );
2578}
2579
2580// Set color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002581void Magick::Image::colorMap ( const size_t index_,
cristy3ed852e2009-09-05 21:47:34 +00002582 const Color &color_ )
2583{
2584 MagickCore::Image* imageptr = image();
2585
2586 if (index_ > (MaxColormapSize-1) )
2587 throwExceptionExplicit( OptionError,
2588 "Colormap index must be less than MaxColormapSize" );
2589
2590 if ( !color_.isValid() )
2591 throwExceptionExplicit( OptionError,
2592 "Color argument is invalid");
2593 modifyImage();
2594
2595 // Ensure that colormap size is large enough
2596 if ( colorMapSize() < (index_+1) )
2597 colorMapSize( index_ + 1 );
2598
2599 // Set color at index in colormap
2600 (imageptr->colormap)[index_] = color_;
2601}
2602// Return color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002603Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
cristy3ed852e2009-09-05 21:47:34 +00002604{
2605 const MagickCore::Image* imageptr = constImage();
2606
2607 if ( !imageptr->colormap )
2608 throwExceptionExplicit( OptionError,
2609 "Image does not contain a colormap");
2610
2611 if ( index_ > imageptr->colors-1 )
2612 throwExceptionExplicit( OptionError,
2613 "Index out of range");
2614
2615 return Magick::Color( (imageptr->colormap)[index_] );
2616}
2617
2618// Colormap size (number of colormap entries)
cristyeaedf062010-05-29 22:36:02 +00002619void Magick::Image::colorMapSize ( const size_t entries_ )
cristy3ed852e2009-09-05 21:47:34 +00002620{
2621 if (entries_ >MaxColormapSize )
2622 throwExceptionExplicit( OptionError,
2623 "Colormap entries must not exceed MaxColormapSize" );
2624
2625 modifyImage();
2626
2627 MagickCore::Image* imageptr = image();
2628
2629 if( !imageptr->colormap )
2630 {
2631 // Allocate colormap
2632 imageptr->colormap =
2633 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2634 imageptr->colors = 0;
2635 }
2636 else if ( entries_ > imageptr->colors )
2637 {
2638 // Re-allocate colormap
2639 imageptr->colormap=(PixelPacket *)
2640 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2641 }
2642
2643 // Initialize any new colormap entries as all black
2644 Color black(0,0,0);
cristyeaedf062010-05-29 22:36:02 +00002645 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
cristy3ed852e2009-09-05 21:47:34 +00002646 (imageptr->colormap)[i] = black;
2647
2648 imageptr->colors = entries_;
2649}
cristyeaedf062010-05-29 22:36:02 +00002650size_t Magick::Image::colorMapSize ( void )
cristy3ed852e2009-09-05 21:47:34 +00002651{
2652 const MagickCore::Image* imageptr = constImage();
2653
2654 if ( !imageptr->colormap )
2655 throwExceptionExplicit( OptionError,
2656 "Image does not contain a colormap");
2657
2658 return imageptr->colors;
2659}
2660
2661// Image colorspace
2662void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2663{
2664 // Nothing to do?
2665 if ( image()->colorspace == colorSpace_ )
2666 return;
2667
2668 modifyImage();
2669
2670 if ( colorSpace_ != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002671 colorSpace_ != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002672 colorSpace_ != TransparentColorspace &&
2673 colorSpace_ != GRAYColorspace )
2674 {
2675 if (image()->colorspace != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002676 image()->colorspace != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002677 image()->colorspace != TransparentColorspace &&
2678 image()->colorspace != GRAYColorspace)
2679 {
2680 /* Transform to RGB colorspace as intermediate step */
2681 TransformRGBImage( image(), image()->colorspace );
2682 throwImageException();
2683 }
2684 /* Transform to final non-RGB colorspace */
2685 RGBTransformImage( image(), colorSpace_ );
2686 throwImageException();
2687 return;
2688 }
2689
2690 if ( colorSpace_ == RGBColorspace ||
cristy510d06a2011-07-06 23:43:54 +00002691 colorSpace_ == sRGBColorspace ||
cristy3ed852e2009-09-05 21:47:34 +00002692 colorSpace_ == TransparentColorspace ||
2693 colorSpace_ == GRAYColorspace )
2694 {
2695 /* Transform to a RGB-type colorspace */
2696 TransformRGBImage( image(), image()->colorspace );
2697 throwImageException();
2698 return;
2699 }
2700}
2701Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2702{
2703 return constImage()->colorspace;
2704}
2705
2706// Set image colorspace type.
2707void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2708{
2709 modifyImage();
2710 options()->colorspaceType( colorSpace_ );
2711}
2712Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2713{
2714 return constOptions()->colorspaceType();
2715}
2716
2717
2718// Comment string
2719void Magick::Image::comment ( const std::string &comment_ )
2720{
2721 modifyImage();
2722 SetImageProperty( image(), "Comment", NULL );
2723 if ( comment_.length() > 0 )
2724 SetImageProperty( image(), "Comment", comment_.c_str() );
2725 throwImageException();
2726}
2727std::string Magick::Image::comment ( void ) const
2728{
2729 const char *value = GetImageProperty( constImage(), "Comment" );
2730
2731 if ( value )
2732 return std::string( value );
2733
2734 return std::string(); // Intentionally no exception
2735}
2736
2737// Composition operator to be used when composition is implicitly used
2738// (such as for image flattening).
2739void Magick::Image::compose (const CompositeOperator compose_)
2740{
2741 image()->compose=compose_;
2742}
2743
2744Magick::CompositeOperator Magick::Image::compose ( void ) const
2745{
2746 return constImage()->compose;
2747}
2748
2749// Compression algorithm
2750void Magick::Image::compressType ( const CompressionType compressType_ )
2751{
2752 modifyImage();
2753 image()->compression = compressType_;
2754 options()->compressType( compressType_ );
2755}
2756Magick::CompressionType Magick::Image::compressType ( void ) const
2757{
2758 return constImage()->compression;
2759}
2760
2761// Enable printing of debug messages from ImageMagick
2762void Magick::Image::debug ( const bool flag_ )
2763{
2764 modifyImage();
2765 options()->debug( flag_ );
2766}
2767bool Magick::Image::debug ( void ) const
2768{
2769 return constOptions()->debug();
2770}
2771
2772// Tagged image format define (set/access coder-specific option) The
2773// magick_ option specifies the coder the define applies to. The key_
2774// option provides the key specific to that coder. The value_ option
2775// provides the value to set (if any). See the defineSet() method if the
2776// key must be removed entirely.
2777void Magick::Image::defineValue ( const std::string &magick_,
2778 const std::string &key_,
2779 const std::string &value_ )
2780{
2781 modifyImage();
2782 std::string format = magick_ + ":" + key_;
2783 std::string option = value_;
2784 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2785}
2786std::string Magick::Image::defineValue ( const std::string &magick_,
2787 const std::string &key_ ) const
2788{
2789 std::string definition = magick_ + ":" + key_;
2790 const char *option =
2791 GetImageOption ( constImageInfo(), definition.c_str() );
2792 if (option)
2793 return std::string( option );
2794 return std::string( );
2795}
2796
2797// Tagged image format define. Similar to the defineValue() method
2798// except that passing the flag_ value 'true' creates a value-less
2799// define with that format and key. Passing the flag_ value 'false'
2800// removes any existing matching definition. The method returns 'true'
2801// if a matching key exists, and 'false' if no matching key exists.
2802void Magick::Image::defineSet ( const std::string &magick_,
2803 const std::string &key_,
2804 bool flag_ )
2805{
2806 modifyImage();
2807 std::string definition = magick_ + ":" + key_;
2808 if (flag_)
2809 {
2810 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2811 }
2812 else
2813 {
2814 DeleteImageOption( imageInfo(), definition.c_str() );
2815 }
2816}
2817bool Magick::Image::defineSet ( const std::string &magick_,
2818 const std::string &key_ ) const
2819{
2820 std::string key = magick_ + ":" + key_;
2821 const char *option =
2822 GetImageOption ( constImageInfo(), key.c_str() );
2823 if (option)
2824 return true;
2825 return false;
2826}
2827
2828// Pixel resolution
2829void Magick::Image::density ( const Geometry &density_ )
2830{
2831 modifyImage();
2832 options()->density( density_ );
2833 if ( density_.isValid() )
2834 {
2835 image()->x_resolution = density_.width();
2836 if ( density_.height() != 0 )
2837 {
2838 image()->y_resolution = density_.height();
2839 }
2840 else
2841 {
2842 image()->y_resolution = density_.width();
2843 }
2844 }
2845 else
2846 {
2847 // Reset to default
2848 image()->x_resolution = 0;
2849 image()->y_resolution = 0;
2850 }
2851}
2852Magick::Geometry Magick::Image::density ( void ) const
2853{
2854 if (isValid())
2855 {
cristy35ef8242010-06-03 16:24:13 +00002856 ssize_t x_resolution=72;
2857 ssize_t y_resolution=72;
cristy3ed852e2009-09-05 21:47:34 +00002858
2859 if (constImage()->x_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002860 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002861
2862 if (constImage()->y_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002863 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002864
2865 return Geometry(x_resolution,y_resolution);
2866 }
2867
2868 return constOptions()->density( );
2869}
2870
2871// Image depth (bits allocated to red/green/blue components)
cristyeaedf062010-05-29 22:36:02 +00002872void Magick::Image::depth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002873{
cristyeaedf062010-05-29 22:36:02 +00002874 size_t depth = depth_;
cristy3ed852e2009-09-05 21:47:34 +00002875
2876 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2877 depth=MAGICKCORE_QUANTUM_DEPTH;
2878
2879 modifyImage();
2880 image()->depth=depth;
2881 options()->depth( depth );
2882}
cristyeaedf062010-05-29 22:36:02 +00002883size_t Magick::Image::depth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002884{
2885 return constImage()->depth;
2886}
2887
2888std::string Magick::Image::directory ( void ) const
2889{
2890 if ( constImage()->directory )
2891 return std::string( constImage()->directory );
2892
2893 throwExceptionExplicit( CorruptImageWarning,
2894 "Image does not contain a directory");
2895
2896 return std::string();
2897}
2898
2899// Endianness (little like Intel or big like SPARC) for image
2900// formats which support endian-specific options.
2901void Magick::Image::endian ( const Magick::EndianType endian_ )
2902{
2903 modifyImage();
2904 options()->endian( endian_ );
2905 image()->endian = endian_;
2906}
2907Magick::EndianType Magick::Image::endian ( void ) const
2908{
2909 return constImage()->endian;
2910}
2911
2912// EXIF profile (BLOB)
2913void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
2914{
2915 modifyImage();
2916 if ( exifProfile_.data() != 0 )
2917 {
2918 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
2919 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
2920 (void) SetImageProfile( image(), "exif", exif_profile);
2921 exif_profile =DestroyStringInfo( exif_profile );
2922 }
2923}
2924Magick::Blob Magick::Image::exifProfile( void ) const
2925{
2926 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
2927 if ( exif_profile == (StringInfo *) NULL)
2928 return Blob( 0, 0 );
2929 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
2930}
2931
2932// Image file name
2933void Magick::Image::fileName ( const std::string &fileName_ )
2934{
2935 modifyImage();
2936
2937 fileName_.copy( image()->filename,
2938 sizeof(image()->filename) - 1 );
2939 image()->filename[ fileName_.length() ] = 0; // Null terminate
2940
2941 options()->fileName( fileName_ );
2942
2943}
2944std::string Magick::Image::fileName ( void ) const
2945{
2946 return constOptions()->fileName( );
2947}
2948
2949// Image file size
2950off_t Magick::Image::fileSize ( void ) const
2951{
2952 return (off_t) GetBlobSize( constImage() );
2953}
2954
2955// Color to use when drawing inside an object
2956void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
2957{
2958 modifyImage();
2959 options()->fillColor(fillColor_);
2960}
2961Magick::Color Magick::Image::fillColor ( void ) const
2962{
2963 return constOptions()->fillColor();
2964}
2965
2966// Rule to use when filling drawn objects
2967void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
2968{
2969 modifyImage();
2970 options()->fillRule(fillRule_);
2971}
2972Magick::FillRule Magick::Image::fillRule ( void ) const
2973{
2974 return constOptions()->fillRule();
2975}
2976
2977// Pattern to use while filling drawn objects.
2978void Magick::Image::fillPattern ( const Image &fillPattern_ )
2979{
2980 modifyImage();
2981 if(fillPattern_.isValid())
2982 options()->fillPattern( fillPattern_.constImage() );
2983 else
2984 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
2985}
2986Magick::Image Magick::Image::fillPattern ( void ) const
2987{
2988 // FIXME: This is inordinately innefficient
2989 Image texture;
2990
2991 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
2992
2993 if ( tmpTexture )
2994 {
2995 ExceptionInfo exceptionInfo;
2996 GetExceptionInfo( &exceptionInfo );
2997 MagickCore::Image* image =
2998 CloneImage( tmpTexture,
2999 0, // columns
3000 0, // rows
3001 MagickTrue, // orphan
3002 &exceptionInfo);
3003 texture.replaceImage( image );
3004 throwException( exceptionInfo );
3005 (void) DestroyExceptionInfo( &exceptionInfo );
3006 }
3007 return texture;
3008}
3009
3010// Filter used by zoom
3011void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3012{
3013 modifyImage();
3014 image()->filter = filterType_;
3015}
3016Magick::FilterTypes Magick::Image::filterType ( void ) const
3017{
3018 return constImage()->filter;
3019}
3020
3021// Font name
3022void Magick::Image::font ( const std::string &font_ )
3023{
3024 modifyImage();
3025 options()->font( font_ );
3026}
3027std::string Magick::Image::font ( void ) const
3028{
3029 return constOptions()->font( );
3030}
3031
3032// Font point size
3033void Magick::Image::fontPointsize ( const double pointSize_ )
3034{
3035 modifyImage();
3036 options()->fontPointsize( pointSize_ );
3037}
3038double Magick::Image::fontPointsize ( void ) const
3039{
3040 return constOptions()->fontPointsize( );
3041}
3042
3043// Font type metrics
3044void Magick::Image::fontTypeMetrics( const std::string &text_,
3045 TypeMetric *metrics )
3046{
3047 DrawInfo *drawInfo = options()->drawInfo();
3048 drawInfo->text = const_cast<char *>(text_.c_str());
3049 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
3050 drawInfo->text = 0;
3051}
3052
3053// Image format string
3054std::string Magick::Image::format ( void ) const
3055{
3056 ExceptionInfo exceptionInfo;
3057 GetExceptionInfo( &exceptionInfo );
3058 const MagickInfo * magick_info
3059 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3060 throwException( exceptionInfo );
3061 (void) DestroyExceptionInfo( &exceptionInfo );
3062
3063 if (( magick_info != 0 ) &&
3064 ( *magick_info->description != '\0' ))
3065 return std::string(magick_info->description);
3066
3067 throwExceptionExplicit( CorruptImageWarning,
3068 "Unrecognized image magick type" );
3069 return std::string();
3070}
3071
3072// Gamma adjustment
3073double Magick::Image::gamma ( void ) const
3074{
3075 return constImage()->gamma;
3076}
3077
3078Magick::Geometry Magick::Image::geometry ( void ) const
3079{
3080 if ( constImage()->geometry )
3081 {
3082 return Geometry(constImage()->geometry);
3083 }
3084
3085 throwExceptionExplicit( OptionWarning,
3086 "Image does not contain a geometry");
3087
3088 return Geometry();
3089}
3090
cristyeaedf062010-05-29 22:36:02 +00003091void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
cristy3ed852e2009-09-05 21:47:34 +00003092{
3093 modifyImage();
3094 image()->dispose = (DisposeType) disposeMethod_;
3095}
cristyeaedf062010-05-29 22:36:02 +00003096size_t Magick::Image::gifDisposeMethod ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003097{
3098 // FIXME: It would be better to return an enumeration
3099 return constImage()->dispose;
3100}
3101
3102// ICC ICM color profile (BLOB)
3103void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3104{
3105 profile("icm",colorProfile_);
3106}
3107Magick::Blob Magick::Image::iccColorProfile( void ) const
3108{
3109 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3110 if ( color_profile == (StringInfo *) NULL)
3111 return Blob( 0, 0 );
3112 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3113}
3114
3115void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3116{
3117 modifyImage();
3118 image()->interlace = interlace_;
3119 options()->interlaceType ( interlace_ );
3120}
3121Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3122{
3123 return constImage()->interlace;
3124}
3125
3126// IPTC profile (BLOB)
3127void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3128{
3129 modifyImage();
3130 if ( iptcProfile_.data() != 0 )
3131 {
3132 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3133 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3134 (void) SetImageProfile( image(), "iptc", iptc_profile);
3135 iptc_profile =DestroyStringInfo( iptc_profile );
3136 }
3137}
3138Magick::Blob Magick::Image::iptcProfile( void ) const
3139{
3140 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3141 if ( iptc_profile == (StringInfo *) NULL)
3142 return Blob( 0, 0 );
3143 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3144}
3145
3146// Does object contain valid image?
3147void Magick::Image::isValid ( const bool isValid_ )
3148{
3149 if ( !isValid_ )
3150 {
3151 delete _imgRef;
3152 _imgRef = new ImageRef;
3153 }
3154 else if ( !isValid() )
3155 {
3156 // Construct with single-pixel black image to make
3157 // image valid. This is an obvious hack.
3158 size( Geometry(1,1) );
3159 read( "xc:#000000" );
3160 }
3161}
3162
3163bool Magick::Image::isValid ( void ) const
3164{
3165 if ( rows() && columns() )
3166 return true;
3167
3168 return false;
3169}
3170
3171// Label image
3172void Magick::Image::label ( const std::string &label_ )
3173{
3174 modifyImage();
3175 SetImageProperty ( image(), "Label", NULL );
3176 if ( label_.length() > 0 )
3177 SetImageProperty ( image(), "Label", label_.c_str() );
3178 throwImageException();
3179}
3180std::string Magick::Image::label ( void ) const
3181{
3182 const char *value = GetImageProperty( constImage(), "Label" );
3183
3184 if ( value )
3185 return std::string( value );
3186
3187 return std::string();
3188}
3189
3190void Magick::Image::magick ( const std::string &magick_ )
3191{
3192 modifyImage();
3193
3194 magick_.copy( image()->magick,
3195 sizeof(image()->magick) - 1 );
3196 image()->magick[ magick_.length() ] = 0;
3197
3198 options()->magick( magick_ );
3199}
3200std::string Magick::Image::magick ( void ) const
3201{
3202 if ( *(constImage()->magick) != '\0' )
3203 return std::string(constImage()->magick);
3204
3205 return constOptions()->magick( );
3206}
3207
3208void Magick::Image::matte ( const bool matteFlag_ )
3209{
3210 modifyImage();
3211
3212 // If matte channel is requested, but image doesn't already have a
3213 // matte channel, then create an opaque matte channel. Likewise, if
3214 // the image already has a matte channel but a matte channel is not
3215 // desired, then set the matte channel to opaque.
3216 if ((matteFlag_ && !constImage()->matte) ||
3217 (constImage()->matte && !matteFlag_))
cristy4c08aed2011-07-01 19:47:50 +00003218 SetImageOpacity(image(),OpaqueAlpha);
cristy3ed852e2009-09-05 21:47:34 +00003219
3220 image()->matte = (MagickBooleanType) matteFlag_;
3221}
3222bool Magick::Image::matte ( void ) const
3223{
3224 if ( constImage()->matte )
3225 return true;
3226 else
3227 return false;
3228}
3229
3230void Magick::Image::matteColor ( const Color &matteColor_ )
3231{
3232 modifyImage();
3233
3234 if ( matteColor_.isValid() )
3235 {
cristy391f1ce2010-09-09 17:23:28 +00003236 image()->matte_color = matteColor_;
3237 options()->matteColor( matteColor_ );
cristy3ed852e2009-09-05 21:47:34 +00003238 }
3239 else
3240 {
3241 // Set to default matte color
3242 Color tmpColor( "#BDBDBD" );
cristy391f1ce2010-09-09 17:23:28 +00003243 image()->matte_color = tmpColor;
cristy3ed852e2009-09-05 21:47:34 +00003244 options()->matteColor( tmpColor );
3245 }
3246}
3247Magick::Color Magick::Image::matteColor ( void ) const
3248{
3249 return Color( constImage()->matte_color.red,
3250 constImage()->matte_color.green,
cristy391f1ce2010-09-09 17:23:28 +00003251 constImage()->matte_color.blue );
cristy3ed852e2009-09-05 21:47:34 +00003252}
3253
3254double Magick::Image::meanErrorPerPixel ( void ) const
3255{
3256 return(constImage()->error.mean_error_per_pixel);
3257}
3258
3259// Image modulus depth (minimum number of bits required to support
3260// red/green/blue components without loss of accuracy)
cristyeaedf062010-05-29 22:36:02 +00003261void Magick::Image::modulusDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00003262{
3263 modifyImage();
3264 SetImageDepth( image(), depth_ );
3265 options()->depth( depth_ );
3266}
cristyeaedf062010-05-29 22:36:02 +00003267size_t Magick::Image::modulusDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003268{
3269 ExceptionInfo exceptionInfo;
3270 GetExceptionInfo( &exceptionInfo );
cristyeaedf062010-05-29 22:36:02 +00003271 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003272 throwException( exceptionInfo );
3273 (void) DestroyExceptionInfo( &exceptionInfo );
3274 return depth;
3275}
3276
3277void Magick::Image::monochrome ( const bool monochromeFlag_ )
3278{
3279 modifyImage();
3280 options()->monochrome( monochromeFlag_ );
3281}
3282bool Magick::Image::monochrome ( void ) const
3283{
3284 return constOptions()->monochrome( );
3285}
3286
3287Magick::Geometry Magick::Image::montageGeometry ( void ) const
3288{
3289 if ( constImage()->montage )
3290 return Magick::Geometry(constImage()->montage);
3291
3292 throwExceptionExplicit( CorruptImageWarning,
3293 "Image does not contain a montage" );
3294
3295 return Magick::Geometry();
3296}
3297
3298double Magick::Image::normalizedMaxError ( void ) const
3299{
3300 return(constImage()->error.normalized_maximum_error);
3301}
3302
3303double Magick::Image::normalizedMeanError ( void ) const
3304{
3305 return constImage()->error.normalized_mean_error;
3306}
3307
3308// Image orientation
3309void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3310{
3311 modifyImage();
3312 image()->orientation = orientation_;
3313}
3314Magick::OrientationType Magick::Image::orientation ( void ) const
3315{
3316 return constImage()->orientation;
3317}
3318
3319void Magick::Image::penColor ( const Color &penColor_ )
3320{
3321 modifyImage();
3322 options()->fillColor(penColor_);
3323 options()->strokeColor(penColor_);
3324}
3325Magick::Color Magick::Image::penColor ( void ) const
3326{
3327 return constOptions()->fillColor();
3328}
3329
3330void Magick::Image::penTexture ( const Image &penTexture_ )
3331{
3332 modifyImage();
3333 if(penTexture_.isValid())
3334 options()->fillPattern( penTexture_.constImage() );
3335 else
3336 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3337}
3338
3339Magick::Image Magick::Image::penTexture ( void ) const
3340{
3341 // FIXME: This is inordinately innefficient
3342 Image texture;
3343
3344 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3345
3346 if ( tmpTexture )
3347 {
3348 ExceptionInfo exceptionInfo;
3349 GetExceptionInfo( &exceptionInfo );
3350 MagickCore::Image* image =
3351 CloneImage( tmpTexture,
3352 0, // columns
3353 0, // rows
3354 MagickTrue, // orphan
3355 &exceptionInfo);
3356 texture.replaceImage( image );
3357 throwException( exceptionInfo );
3358 (void) DestroyExceptionInfo( &exceptionInfo );
3359 }
3360 return texture;
3361}
3362
3363// Set the color of a pixel.
cristy35ef8242010-06-03 16:24:13 +00003364void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00003365 const Color &color_ )
3366{
3367 // Test arguments to ensure they are within the image.
cristy07fb9182010-06-06 23:37:14 +00003368 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
cristy3ed852e2009-09-05 21:47:34 +00003369 throwExceptionExplicit( OptionError,
3370 "Access outside of image boundary" );
3371
3372 modifyImage();
3373
3374 // Set image to DirectClass
3375 classType( DirectClass );
3376
3377 // Get pixel view
3378 Pixels pixels(*this);
3379 // Set pixel value
cristy4c08aed2011-07-01 19:47:50 +00003380 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3381 PixelPacket packet = color_;
3382 MagickCore::SetPixelPacket(constImage(),&packet,pixel);
cristy3ed852e2009-09-05 21:47:34 +00003383 // Tell ImageMagick that pixels have been updated
3384 pixels.sync();
3385
3386 return;
3387}
3388
3389// Get the color of a pixel
cristy35ef8242010-06-03 16:24:13 +00003390Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3391 const ssize_t y_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003392{
3393 ClassType storage_class;
3394 storage_class = classType();
3395 // DirectClass
cristy4c08aed2011-07-01 19:47:50 +00003396 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3397 if ( pixel )
cristy3ed852e2009-09-05 21:47:34 +00003398 {
cristy4c08aed2011-07-01 19:47:50 +00003399 PixelPacket packet;
3400 MagickCore::GetPixelPacket(constImage(),pixel,&packet);
3401 return Color( packet );
cristy3ed852e2009-09-05 21:47:34 +00003402 }
3403
3404 return Color(); // invalid
3405}
3406
3407// Preferred size and location of an image canvas.
3408void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3409{
3410 modifyImage();
3411 options()->page( pageSize_ );
3412 image()->page = pageSize_;
3413}
3414Magick::Geometry Magick::Image::page ( void ) const
3415{
3416 return Geometry( constImage()->page.width,
3417 constImage()->page.height,
3418 AbsoluteValue(constImage()->page.x),
3419 AbsoluteValue(constImage()->page.y),
3420 constImage()->page.x < 0 ? true : false,
3421 constImage()->page.y < 0 ? true : false);
3422}
3423
3424// Add a named profile to an image or remove a named profile by
3425// passing an empty Blob (use default Blob constructor).
3426// Valid names are:
3427// "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3428void Magick::Image::profile( const std::string name_,
3429 const Magick::Blob &profile_ )
3430{
3431 modifyImage();
cristyd99b0962010-05-29 23:14:26 +00003432 ssize_t result = ProfileImage( image(), name_.c_str(),
cristy3ed852e2009-09-05 21:47:34 +00003433 (unsigned char *)profile_.data(),
3434 profile_.length(), MagickTrue);
3435
3436 if( !result )
3437 throwImageException();
3438}
3439
3440// Retrieve a named profile from the image.
3441// Valid names are:
3442// "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3443// an existing generic profile name.
3444Magick::Blob Magick::Image::profile( const std::string name_ ) const
3445{
3446 const MagickCore::Image* image = constImage();
3447
3448 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3449
3450 if ( profile != (StringInfo *) NULL)
3451 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3452
3453 Blob blob;
3454 Image temp_image = *this;
3455 temp_image.write( &blob, name_ );
3456 return blob;
3457}
3458
cristyeaedf062010-05-29 22:36:02 +00003459void Magick::Image::quality ( const size_t quality_ )
cristy3ed852e2009-09-05 21:47:34 +00003460{
3461 modifyImage();
3462 image()->quality = quality_;
3463 options()->quality( quality_ );
3464}
cristyeaedf062010-05-29 22:36:02 +00003465size_t Magick::Image::quality ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003466{
3467 return constImage()->quality;
3468}
3469
cristyeaedf062010-05-29 22:36:02 +00003470void Magick::Image::quantizeColors ( const size_t colors_ )
cristy3ed852e2009-09-05 21:47:34 +00003471{
3472 modifyImage();
3473 options()->quantizeColors( colors_ );
3474}
cristyeaedf062010-05-29 22:36:02 +00003475size_t Magick::Image::quantizeColors ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003476{
3477 return constOptions()->quantizeColors( );
3478}
3479
3480void Magick::Image::quantizeColorSpace
3481 ( const Magick::ColorspaceType colorSpace_ )
3482{
3483 modifyImage();
3484 options()->quantizeColorSpace( colorSpace_ );
3485}
3486Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3487{
3488 return constOptions()->quantizeColorSpace( );
3489}
3490
3491void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3492{
3493 modifyImage();
3494 options()->quantizeDither( ditherFlag_ );
3495}
3496bool Magick::Image::quantizeDither ( void ) const
3497{
3498 return constOptions()->quantizeDither( );
3499}
3500
cristyeaedf062010-05-29 22:36:02 +00003501void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
cristy3ed852e2009-09-05 21:47:34 +00003502{
3503 modifyImage();
3504 options()->quantizeTreeDepth( treeDepth_ );
3505}
cristyeaedf062010-05-29 22:36:02 +00003506size_t Magick::Image::quantizeTreeDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003507{
3508 return constOptions()->quantizeTreeDepth( );
3509}
3510
3511void Magick::Image::renderingIntent
3512 ( const Magick::RenderingIntent renderingIntent_ )
3513{
3514 modifyImage();
3515 image()->rendering_intent = renderingIntent_;
3516}
3517Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3518{
3519 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3520}
3521
3522void Magick::Image::resolutionUnits
3523 ( const Magick::ResolutionType resolutionUnits_ )
3524{
3525 modifyImage();
3526 image()->units = resolutionUnits_;
3527 options()->resolutionUnits( resolutionUnits_ );
3528}
3529Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3530{
3531 return constOptions()->resolutionUnits( );
3532}
3533
cristyeaedf062010-05-29 22:36:02 +00003534void Magick::Image::scene ( const size_t scene_ )
cristy3ed852e2009-09-05 21:47:34 +00003535{
3536 modifyImage();
3537 image()->scene = scene_;
3538}
cristyeaedf062010-05-29 22:36:02 +00003539size_t Magick::Image::scene ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003540{
3541 return constImage()->scene;
3542}
3543
3544std::string Magick::Image::signature ( const bool force_ ) const
3545{
3546 Lock( &_imgRef->_mutexLock );
3547
3548 // Re-calculate image signature if necessary
3549 if ( force_ ||
3550 !GetImageProperty(constImage(), "Signature") ||
3551 constImage()->taint )
3552 {
3553 SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
3554 }
3555
3556 const char *property = GetImageProperty(constImage(), "Signature");
3557
3558 return std::string( property );
3559}
3560
3561void Magick::Image::size ( const Geometry &geometry_ )
3562{
3563 modifyImage();
3564 options()->size( geometry_ );
3565 image()->rows = geometry_.height();
3566 image()->columns = geometry_.width();
3567}
3568Magick::Geometry Magick::Image::size ( void ) const
3569{
3570 return Magick::Geometry( constImage()->columns, constImage()->rows );
3571}
3572
cristy8198a752009-09-28 23:59:24 +00003573// Splice image
3574void Magick::Image::splice( const Geometry &geometry_ )
3575{
3576 RectangleInfo spliceInfo = geometry_;
3577 ExceptionInfo exceptionInfo;
3578 GetExceptionInfo( &exceptionInfo );
3579 MagickCore::Image* newImage =
3580 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3581 replaceImage( newImage );
3582 throwException( exceptionInfo );
3583 (void) DestroyExceptionInfo( &exceptionInfo );
3584}
3585
cristy3ed852e2009-09-05 21:47:34 +00003586// Obtain image statistics. Statistics are normalized to the range of
3587// 0.0 to 1.0 and are output to the specified ImageStatistics
3588// structure.
cristyd42d9952011-07-08 14:21:50 +00003589void Magick::Image::statistics ( ImageStatistics *statistics )
cristy3ed852e2009-09-05 21:47:34 +00003590{
3591 double
3592 maximum,
3593 minimum;
3594
3595 ExceptionInfo exceptionInfo;
3596 GetExceptionInfo( &exceptionInfo );
cristyd42d9952011-07-08 14:21:50 +00003597
cristyed231572011-07-14 02:18:59 +00003598 PushPixelChannelMap( image(), RedChannel);
cristyd42d9952011-07-08 14:21:50 +00003599 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003600 statistics->red.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003601 statistics->red.maximum=maximum;
3602 (void) GetImageMean( image(),&statistics->red.mean,
3603 &statistics->red.standard_deviation,&exceptionInfo);
3604 (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
3605 &statistics->red.skewness,&exceptionInfo);
cristyed231572011-07-14 02:18:59 +00003606 PopPixelChannelMap( image() );
cristyd42d9952011-07-08 14:21:50 +00003607
cristyed231572011-07-14 02:18:59 +00003608 PushPixelChannelMap( image(), GreenChannel);
cristyd42d9952011-07-08 14:21:50 +00003609 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003610 statistics->green.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003611 statistics->green.maximum=maximum;
3612 (void) GetImageMean( image(),&statistics->green.mean,
3613 &statistics->green.standard_deviation,&exceptionInfo);
3614 (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
3615 &statistics->green.skewness,&exceptionInfo);
cristyed231572011-07-14 02:18:59 +00003616 PopPixelChannelMap( image() );
cristyd42d9952011-07-08 14:21:50 +00003617
cristyed231572011-07-14 02:18:59 +00003618 PushPixelChannelMap( image(), GreenChannel);
cristyd42d9952011-07-08 14:21:50 +00003619 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003620 statistics->blue.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003621 statistics->blue.maximum=maximum;
3622 (void) GetImageMean( image(),&statistics->blue.mean,
3623 &statistics->blue.standard_deviation,&exceptionInfo);
3624 (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
3625 &statistics->blue.skewness,&exceptionInfo);
cristyed231572011-07-14 02:18:59 +00003626 PopPixelChannelMap( image() );
cristyd42d9952011-07-08 14:21:50 +00003627
cristyed231572011-07-14 02:18:59 +00003628 PushPixelChannelMap( image(), AlphaChannel);
cristyd42d9952011-07-08 14:21:50 +00003629 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy4c08aed2011-07-01 19:47:50 +00003630 statistics->alpha.minimum=minimum;
3631 statistics->alpha.maximum=maximum;
cristyd42d9952011-07-08 14:21:50 +00003632 (void) GetImageMean( image(),&statistics->alpha.mean,
3633 &statistics->alpha.standard_deviation,&exceptionInfo);
3634 (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
3635 &statistics->alpha.skewness,&exceptionInfo);
cristyed231572011-07-14 02:18:59 +00003636 PopPixelChannelMap( image() );
cristyd42d9952011-07-08 14:21:50 +00003637
cristy3ed852e2009-09-05 21:47:34 +00003638 throwException( exceptionInfo );
3639 (void) DestroyExceptionInfo( &exceptionInfo );
3640}
3641
cristy9f89a3f2011-02-12 17:02:35 +00003642// Strip strips an image of all profiles and comments.
3643void Magick::Image::strip ( void )
3644{
3645 modifyImage();
3646 StripImage( image() );
3647 throwImageException();
3648}
3649
cristy3ed852e2009-09-05 21:47:34 +00003650// enabled/disable stroke anti-aliasing
3651void Magick::Image::strokeAntiAlias ( const bool flag_ )
3652{
3653 modifyImage();
3654 options()->strokeAntiAlias(flag_);
3655}
3656bool Magick::Image::strokeAntiAlias ( void ) const
3657{
3658 return constOptions()->strokeAntiAlias();
3659}
3660
3661// Color to use when drawing object outlines
3662void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3663{
3664 modifyImage();
3665 options()->strokeColor(strokeColor_);
3666}
3667Magick::Color Magick::Image::strokeColor ( void ) const
3668{
3669 return constOptions()->strokeColor();
3670}
3671
3672// dash pattern for drawing vector objects (default one)
3673void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3674{
3675 modifyImage();
3676 options()->strokeDashArray( strokeDashArray_ );
3677}
3678
3679const double* Magick::Image::strokeDashArray ( void ) const
3680{
3681 return constOptions()->strokeDashArray( );
3682}
3683
3684// dash offset for drawing vector objects (default one)
3685void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3686{
3687 modifyImage();
3688 options()->strokeDashOffset( strokeDashOffset_ );
3689}
3690
3691double Magick::Image::strokeDashOffset ( void ) const
3692{
3693 return constOptions()->strokeDashOffset( );
3694}
3695
3696// Specify the shape to be used at the end of open subpaths when they
3697// are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3698// and SquareCap.
3699void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3700{
3701 modifyImage();
3702 options()->strokeLineCap( lineCap_ );
3703}
3704Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3705{
3706 return constOptions()->strokeLineCap( );
3707}
3708
3709// Specify the shape to be used at the corners of paths (or other
3710// vector shapes) when they are stroked. Values of LineJoin are
3711// UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3712void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3713{
3714 modifyImage();
3715 options()->strokeLineJoin( lineJoin_ );
3716}
3717Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3718{
3719 return constOptions()->strokeLineJoin( );
3720}
3721
3722// Specify miter limit. When two line segments meet at a sharp angle
3723// and miter joins have been specified for 'lineJoin', it is possible
3724// for the miter to extend far beyond the thickness of the line
3725// stroking the path. The miterLimit' imposes a limit on the ratio of
3726// the miter length to the 'lineWidth'. The default value of this
3727// parameter is 4.
cristyeaedf062010-05-29 22:36:02 +00003728void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
cristy3ed852e2009-09-05 21:47:34 +00003729{
3730 modifyImage();
3731 options()->strokeMiterLimit( strokeMiterLimit_ );
3732}
cristyeaedf062010-05-29 22:36:02 +00003733size_t Magick::Image::strokeMiterLimit ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003734{
3735 return constOptions()->strokeMiterLimit( );
3736}
3737
3738// Pattern to use while stroking drawn objects.
3739void Magick::Image::strokePattern ( const Image &strokePattern_ )
3740{
3741 modifyImage();
3742 if(strokePattern_.isValid())
3743 options()->strokePattern( strokePattern_.constImage() );
3744 else
3745 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3746}
3747Magick::Image Magick::Image::strokePattern ( void ) const
3748{
3749 // FIXME: This is inordinately innefficient
3750 Image texture;
3751
3752 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3753
3754 if ( tmpTexture )
3755 {
3756 ExceptionInfo exceptionInfo;
3757 GetExceptionInfo( &exceptionInfo );
3758 MagickCore::Image* image =
3759 CloneImage( tmpTexture,
3760 0, // columns
3761 0, // rows
3762 MagickTrue, // orphan
3763 &exceptionInfo);
3764 throwException( exceptionInfo );
3765 (void) DestroyExceptionInfo( &exceptionInfo );
3766 texture.replaceImage( image );
3767 }
3768 return texture;
3769}
3770
3771// Stroke width for drawing lines, circles, ellipses, etc.
3772void Magick::Image::strokeWidth ( const double strokeWidth_ )
3773{
3774 modifyImage();
3775 options()->strokeWidth( strokeWidth_ );
3776}
3777double Magick::Image::strokeWidth ( void ) const
3778{
3779 return constOptions()->strokeWidth( );
3780}
3781
cristyeaedf062010-05-29 22:36:02 +00003782void Magick::Image::subImage ( const size_t subImage_ )
cristy3ed852e2009-09-05 21:47:34 +00003783{
3784 modifyImage();
3785 options()->subImage( subImage_ );
3786}
cristyeaedf062010-05-29 22:36:02 +00003787size_t Magick::Image::subImage ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003788{
3789 return constOptions()->subImage( );
3790}
3791
cristyeaedf062010-05-29 22:36:02 +00003792void Magick::Image::subRange ( const size_t subRange_ )
cristy3ed852e2009-09-05 21:47:34 +00003793{
3794 modifyImage();
3795 options()->subRange( subRange_ );
3796}
cristyeaedf062010-05-29 22:36:02 +00003797size_t Magick::Image::subRange ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003798{
3799 return constOptions()->subRange( );
3800}
3801
3802// Annotation text encoding (e.g. "UTF-16")
3803void Magick::Image::textEncoding ( const std::string &encoding_ )
3804{
3805 modifyImage();
3806 options()->textEncoding( encoding_ );
3807}
3808std::string Magick::Image::textEncoding ( void ) const
3809{
3810 return constOptions()->textEncoding( );
3811}
3812
cristybb503372010-05-27 20:51:26 +00003813size_t Magick::Image::totalColors ( void )
cristy3ed852e2009-09-05 21:47:34 +00003814{
3815 ExceptionInfo exceptionInfo;
3816 GetExceptionInfo( &exceptionInfo );
cristybb503372010-05-27 20:51:26 +00003817 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003818 throwException( exceptionInfo );
3819 (void) DestroyExceptionInfo( &exceptionInfo );
3820 return colors;
3821}
3822
3823// Origin of coordinate system to use when annotating with text or drawing
3824void Magick::Image::transformOrigin ( const double x_, const double y_ )
3825{
3826 modifyImage();
3827 options()->transformOrigin( x_, y_ );
3828}
3829
3830// Rotation to use when annotating with text or drawing
3831void Magick::Image::transformRotation ( const double angle_ )
3832{
3833 modifyImage();
3834 options()->transformRotation( angle_ );
3835}
3836
3837// Reset transformation parameters to default
3838void Magick::Image::transformReset ( void )
3839{
3840 modifyImage();
3841 options()->transformReset();
3842}
3843
3844// Scale to use when annotating with text or drawing
3845void Magick::Image::transformScale ( const double sx_, const double sy_ )
3846{
3847 modifyImage();
3848 options()->transformScale( sx_, sy_ );
3849}
3850
3851// Skew to use in X axis when annotating with text or drawing
3852void Magick::Image::transformSkewX ( const double skewx_ )
3853{
3854 modifyImage();
3855 options()->transformSkewX( skewx_ );
3856}
3857
3858// Skew to use in Y axis when annotating with text or drawing
3859void Magick::Image::transformSkewY ( const double skewy_ )
3860{
3861 modifyImage();
3862 options()->transformSkewY( skewy_ );
3863}
3864
3865// Image representation type
3866Magick::ImageType Magick::Image::type ( void ) const
3867{
3868
3869 ExceptionInfo exceptionInfo;
3870 GetExceptionInfo( &exceptionInfo );
3871 ImageType image_type = constOptions()->type();
3872 if ( image_type == UndefinedType )
3873 image_type= GetImageType( constImage(), &exceptionInfo);
3874 throwException( exceptionInfo );
3875 (void) DestroyExceptionInfo( &exceptionInfo );
3876 return image_type;
3877}
3878void Magick::Image::type ( const Magick::ImageType type_)
3879{
3880 modifyImage();
3881 options()->type( type_ );
3882 SetImageType( image(), type_ );
3883}
3884
3885void Magick::Image::verbose ( const bool verboseFlag_ )
3886{
3887 modifyImage();
3888 options()->verbose( verboseFlag_ );
3889}
3890bool Magick::Image::verbose ( void ) const
3891{
3892 return constOptions()->verbose( );
3893}
3894
3895void Magick::Image::view ( const std::string &view_ )
3896{
3897 modifyImage();
3898 options()->view( view_ );
3899}
3900std::string Magick::Image::view ( void ) const
3901{
3902 return constOptions()->view( );
3903}
3904
3905// Virtual pixel method
3906void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
3907{
3908 modifyImage();
3909 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
3910 options()->virtualPixelMethod( virtual_pixel_method_ );
3911}
3912Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
3913{
3914 return GetImageVirtualPixelMethod( constImage() );
3915}
3916
3917void Magick::Image::x11Display ( const std::string &display_ )
3918{
3919 modifyImage();
3920 options()->x11Display( display_ );
3921}
3922std::string Magick::Image::x11Display ( void ) const
3923{
3924 return constOptions()->x11Display( );
3925}
3926
3927double Magick::Image::xResolution ( void ) const
3928{
3929 return constImage()->x_resolution;
3930}
3931double Magick::Image::yResolution ( void ) const
3932{
3933 return constImage()->y_resolution;
3934}
3935
3936// Copy Constructor
3937Magick::Image::Image( const Image & image_ )
3938 : _imgRef(image_._imgRef)
3939{
3940 Lock( &_imgRef->_mutexLock );
3941
3942 // Increase reference count
3943 ++_imgRef->_refCount;
3944}
3945
3946// Assignment operator
3947Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
3948{
3949 if( this != &image_ )
3950 {
3951 {
3952 Lock( &image_._imgRef->_mutexLock );
3953 ++image_._imgRef->_refCount;
3954 }
3955
3956 bool doDelete = false;
3957 {
3958 Lock( &_imgRef->_mutexLock );
3959 if ( --_imgRef->_refCount == 0 )
3960 doDelete = true;
3961 }
3962
3963 if ( doDelete )
3964 {
3965 // Delete old image reference with associated image and options.
3966 delete _imgRef;
3967 _imgRef = 0;
3968 }
3969 // Use new image reference
3970 _imgRef = image_._imgRef;
3971 }
3972
3973 return *this;
3974}
3975
3976//////////////////////////////////////////////////////////////////////
3977//
3978// Low-level Pixel Access Routines
3979//
3980// Also see the Pixels class, which provides support for multiple
3981// cache views. The low-level pixel access routines in the Image
3982// class are provided in order to support backward compatability.
3983//
3984//////////////////////////////////////////////////////////////////////
3985
3986// Transfers read-only pixels from the image to the pixel cache as
3987// defined by the specified region
cristy4c08aed2011-07-01 19:47:50 +00003988const Magick::Quantum* Magick::Image::getConstPixels
cristyd99b0962010-05-29 23:14:26 +00003989 ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00003990 const size_t columns_,
3991 const size_t rows_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003992{
3993 ExceptionInfo exceptionInfo;
3994 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00003995 const Quantum* p = (*GetVirtualPixels)( constImage(),
cristy3ed852e2009-09-05 21:47:34 +00003996 x_, y_,
3997 columns_, rows_,
3998 &exceptionInfo );
3999 throwException( exceptionInfo );
4000 (void) DestroyExceptionInfo( &exceptionInfo );
4001 return p;
4002}
4003
cristy4c08aed2011-07-01 19:47:50 +00004004// Obtain read-only pixel associated pixels channels
4005const void* Magick::Image::getConstMetacontent ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00004006{
cristy4c08aed2011-07-01 19:47:50 +00004007 const void* result = GetVirtualMetacontent( constImage() );
cristy3ed852e2009-09-05 21:47:34 +00004008
4009 if( !result )
4010 throwImageException();
4011
4012 return result;
4013}
4014
cristy4c08aed2011-07-01 19:47:50 +00004015// Obtain image pixel associated pixels channels
4016void* Magick::Image::getMetacontent ( void )
cristy3ed852e2009-09-05 21:47:34 +00004017{
cristy4c08aed2011-07-01 19:47:50 +00004018 void* result = GetAuthenticMetacontent( image() );
cristy3ed852e2009-09-05 21:47:34 +00004019
4020 if( !result )
4021 throwImageException();
4022
4023 return ( result );
4024}
4025
4026// Transfers pixels from the image to the pixel cache as defined
4027// by the specified region. Modified pixels may be subsequently
4028// transferred back to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00004029Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00004030 const size_t columns_,
4031 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00004032{
4033 modifyImage();
4034 ExceptionInfo exceptionInfo;
4035 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00004036 Quantum* result = (*GetAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00004037 x_, y_,
4038 columns_, rows_, &exceptionInfo );
4039 throwException( exceptionInfo );
4040 (void) DestroyExceptionInfo( &exceptionInfo );
4041
4042 return result;
4043}
4044
4045// Allocates a pixel cache region to store image pixels as defined
4046// by the region rectangle. This area is subsequently transferred
4047// from the pixel cache to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00004048Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00004049 const size_t columns_,
4050 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00004051{
4052 modifyImage();
4053 ExceptionInfo exceptionInfo;
4054 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00004055 Quantum* result = (*QueueAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00004056 x_, y_,
4057 columns_, rows_, &exceptionInfo );
4058 throwException( exceptionInfo );
4059 (void) DestroyExceptionInfo( &exceptionInfo );
4060
4061 return result;
4062}
4063
4064// Transfers the image cache pixels to the image.
4065void Magick::Image::syncPixels ( void )
4066{
4067 ExceptionInfo exceptionInfo;
4068 GetExceptionInfo( &exceptionInfo );
4069 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4070 throwException( exceptionInfo );
4071 (void) DestroyExceptionInfo( &exceptionInfo );
4072}
4073
4074// Transfers one or more pixel components from a buffer or file
4075// into the image pixel cache of an image.
4076// Used to support image decoders.
4077void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4078 const unsigned char *source_ )
4079{
4080 QuantumInfo
4081 *quantum_info;
4082
4083 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4084 ExceptionInfo exceptionInfo;
4085 GetExceptionInfo( &exceptionInfo );
4086 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4087 quantum_,source_, &exceptionInfo);
4088 throwException( exceptionInfo );
4089 (void) DestroyExceptionInfo( &exceptionInfo );
4090 quantum_info=DestroyQuantumInfo(quantum_info);
4091}
4092
4093// Transfers one or more pixel components from the image pixel
4094// cache to a buffer or file.
4095// Used to support image encoders.
4096void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4097 unsigned char *destination_ )
4098{
4099 QuantumInfo
4100 *quantum_info;
4101
4102 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4103 ExceptionInfo exceptionInfo;
4104 GetExceptionInfo( &exceptionInfo );
4105 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4106 quantum_,destination_, &exceptionInfo);
4107 quantum_info=DestroyQuantumInfo(quantum_info);
4108 throwException( exceptionInfo );
4109 (void) DestroyExceptionInfo( &exceptionInfo );
4110}
4111
4112/////////////////////////////////////////////////////////////////////
4113//
4114// No end-user methods beyond this point
4115//
4116/////////////////////////////////////////////////////////////////////
4117
4118
4119//
4120// Construct using existing image and default options
4121//
4122Magick::Image::Image ( MagickCore::Image* image_ )
4123 : _imgRef(new ImageRef( image_))
4124{
4125}
4126
4127// Get Magick::Options*
4128Magick::Options* Magick::Image::options( void )
4129{
4130 return _imgRef->options();
4131}
4132const Magick::Options* Magick::Image::constOptions( void ) const
4133{
4134 return _imgRef->options();
4135}
4136
4137// Get MagickCore::Image*
4138MagickCore::Image*& Magick::Image::image( void )
4139{
4140 return _imgRef->image();
4141}
4142const MagickCore::Image* Magick::Image::constImage( void ) const
4143{
4144 return _imgRef->image();
4145}
4146
4147// Get ImageInfo *
4148MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4149{
4150 return _imgRef->options()->imageInfo();
4151}
4152const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4153{
4154 return _imgRef->options()->imageInfo();
4155}
4156
4157// Get QuantizeInfo *
4158MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4159{
4160 return _imgRef->options()->quantizeInfo();
4161}
4162const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4163{
4164 return _imgRef->options()->quantizeInfo();
4165}
4166
4167//
4168// Replace current image
4169//
4170MagickCore::Image * Magick::Image::replaceImage
4171 ( MagickCore::Image* replacement_ )
4172{
4173 MagickCore::Image* image;
4174
4175 if( replacement_ )
4176 image = replacement_;
4177 else
4178 image = AcquireImage(constImageInfo());
4179
4180 {
4181 Lock( &_imgRef->_mutexLock );
4182
4183 if ( _imgRef->_refCount == 1 )
4184 {
4185 // We own the image, just replace it, and de-register
4186 _imgRef->id( -1 );
4187 _imgRef->image(image);
4188 }
4189 else
4190 {
4191 // We don't own the image, dereference and replace with copy
4192 --_imgRef->_refCount;
4193 _imgRef = new ImageRef( image, constOptions() );
4194 }
4195 }
4196
4197 return _imgRef->_image;
4198}
4199
4200//
4201// Prepare to modify image or image options
4202// Replace current image and options with copy if reference count > 1
4203//
4204void Magick::Image::modifyImage( void )
4205{
4206 {
4207 Lock( &_imgRef->_mutexLock );
4208 if ( _imgRef->_refCount == 1 )
4209 {
4210 // De-register image and return
4211 _imgRef->id( -1 );
4212 return;
4213 }
4214 }
4215
4216 ExceptionInfo exceptionInfo;
4217 GetExceptionInfo( &exceptionInfo );
4218 replaceImage( CloneImage( image(),
4219 0, // columns
4220 0, // rows
4221 MagickTrue, // orphan
4222 &exceptionInfo) );
4223 throwException( exceptionInfo );
4224 (void) DestroyExceptionInfo( &exceptionInfo );
4225 return;
4226}
4227
4228//
4229// Test for an ImageMagick reported error and throw exception if one
4230// has been reported. Secretly resets image->exception back to default
4231// state even though this method is const.
4232//
4233void Magick::Image::throwImageException( void ) const
4234{
4235 // Throw C++ exception while resetting Image exception to default state
4236 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4237}
4238
4239// Register image with image registry or obtain registration id
cristybb503372010-05-27 20:51:26 +00004240ssize_t Magick::Image::registerId( void )
cristy3ed852e2009-09-05 21:47:34 +00004241{
4242 Lock( &_imgRef->_mutexLock );
4243 if( _imgRef->id() < 0 )
4244 {
4245 char id[MaxTextExtent];
4246 ExceptionInfo exceptionInfo;
4247 GetExceptionInfo( &exceptionInfo );
4248 _imgRef->id(_imgRef->id()+1);
cristye8c25f92010-06-03 00:53:06 +00004249 sprintf(id,"%.20g\n",(double) _imgRef->id());
cristy3ed852e2009-09-05 21:47:34 +00004250 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4251 throwException( exceptionInfo );
4252 (void) DestroyExceptionInfo( &exceptionInfo );
4253 }
4254 return _imgRef->id();
4255}
4256
4257// Unregister image from image registry
4258void Magick::Image::unregisterId( void )
4259{
4260 modifyImage();
4261 _imgRef->id( -1 );
4262}
4263
4264//
4265// Create a local wrapper around MagickCoreTerminus
4266//
4267namespace Magick
4268{
4269 extern "C" {
4270 void MagickPlusPlusDestroyMagick(void);
4271 }
4272}
4273
4274void Magick::MagickPlusPlusDestroyMagick(void)
4275{
4276 if (magick_initialized)
4277 {
4278 magick_initialized=false;
4279 MagickCore::MagickCoreTerminus();
4280 }
4281}
4282
4283// C library initialization routine
4284void MagickDLLDecl Magick::InitializeMagick(const char *path_)
4285{
4286 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4287 if (!magick_initialized)
4288 magick_initialized=true;
4289}
4290
4291//
4292// Cleanup class to ensure that ImageMagick singletons are destroyed
4293// so as to avoid any resemblence to a memory leak (which seems to
4294// confuse users)
4295//
4296namespace Magick
4297{
4298
4299 class MagickCleanUp
4300 {
4301 public:
4302 MagickCleanUp( void );
4303 ~MagickCleanUp( void );
4304 };
4305
4306 // The destructor for this object is invoked when the destructors for
4307 // static objects in this translation unit are invoked.
4308 static MagickCleanUp magickCleanUpGuard;
4309}
4310
4311Magick::MagickCleanUp::MagickCleanUp ( void )
4312{
4313 // Don't even think about invoking InitializeMagick here!
4314}
4315
4316Magick::MagickCleanUp::~MagickCleanUp ( void )
4317{
4318 MagickPlusPlusDestroyMagick();
4319}