blob: 81d9a7147f2fd5696e9813dd10bd2c250f49dd66 [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>
cristyeafe4ab2010-05-06 19:43:12 +000016#if !defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +000017#include <strings.h>
18#endif
cristy4c08aed2011-07-01 19:47:50 +000019#include "Magick++/Include.h"
cristy3ed852e2009-09-05 21:47:34 +000020
21using namespace std;
22
23#include "Magick++/Image.h"
24#include "Magick++/Functions.h"
25#include "Magick++/Pixels.h"
26#include "Magick++/Options.h"
27#include "Magick++/ImageRef.h"
28
29#define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
cristy3ed852e2009-09-05 21:47:34 +000030#define DegreesToRadians(x) (MagickPI*(x)/180.0)
31
32MagickDLLDeclExtern const char *Magick::borderGeometryDefault = "6x6+0+0";
33MagickDLLDeclExtern const char *Magick::frameGeometryDefault = "25x25+6+6";
34MagickDLLDeclExtern const char *Magick::raiseGeometryDefault = "6x6+0+0";
35
36static bool magick_initialized=false;
37
38//
39// Explicit template instantiations
40//
41
42//
43// Friend functions to compare Image objects
44//
45
cristy4e0eef02010-05-30 21:52:21 +000046MagickDLLDecl int Magick::operator == ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000047 const Magick::Image& right_ )
48{
49 // If image pixels and signature are the same, then the image is identical
50 return ( ( left_.rows() == right_.rows() ) &&
51 ( left_.columns() == right_.columns() ) &&
52 ( left_.signature() == right_.signature() )
53 );
54}
cristy4e0eef02010-05-30 21:52:21 +000055MagickDLLDecl int Magick::operator != ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000056 const Magick::Image& right_ )
57{
58 return ( ! (left_ == right_) );
59}
cristy4e0eef02010-05-30 21:52:21 +000060MagickDLLDecl int Magick::operator > ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000061 const Magick::Image& right_ )
62{
63 return ( !( left_ < right_ ) && ( left_ != right_ ) );
64}
cristy4e0eef02010-05-30 21:52:21 +000065MagickDLLDecl int Magick::operator < ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000066 const Magick::Image& right_ )
67{
68 // If image pixels are less, then image is smaller
69 return ( ( left_.rows() * left_.columns() ) <
70 ( right_.rows() * right_.columns() )
71 );
72}
cristy4e0eef02010-05-30 21:52:21 +000073MagickDLLDecl int Magick::operator >= ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000074 const Magick::Image& right_ )
75{
76 return ( ( left_ > right_ ) || ( left_ == right_ ) );
77}
cristy4e0eef02010-05-30 21:52:21 +000078MagickDLLDecl int Magick::operator <= ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000079 const Magick::Image& right_ )
80{
81 return ( ( left_ < right_ ) || ( left_ == right_ ) );
82}
83
84//
85// Image object implementation
86//
87
88// Construct from image file or image specification
89Magick::Image::Image( const std::string &imageSpec_ )
90 : _imgRef(new ImageRef)
91{
92 try
93 {
94 // Initialize, Allocate and Read images
95 read( imageSpec_ );
96 }
97 catch ( const Warning & /*warning_*/ )
98 {
99 // FIXME: need a way to report warnings in constructor
100 }
101 catch ( const Error & /*error_*/ )
102 {
103 // Release resources
104 delete _imgRef;
105 throw;
106 }
107}
108
109// Construct a blank image canvas of specified size and color
110Magick::Image::Image( const Geometry &size_,
111 const Color &color_ )
112 : _imgRef(new ImageRef)
113{
114 // xc: prefix specifies an X11 color string
115 std::string imageSpec("xc:");
116 imageSpec += color_;
117
118 try
119 {
120 // Set image size
121 size( size_ );
122
123 // Initialize, Allocate and Read images
124 read( imageSpec );
125 }
126 catch ( const Warning & /*warning_*/ )
127 {
128 // FIXME: need a way to report warnings in constructor
129 }
130 catch ( const Error & /*error_*/ )
131 {
132 // Release resources
133 delete _imgRef;
134 throw;
135 }
136}
137
138// Construct Image from in-memory BLOB
139Magick::Image::Image ( const Blob &blob_ )
140 : _imgRef(new ImageRef)
141{
142 try
143 {
144 // Initialize, Allocate and Read images
145 read( blob_ );
146 }
147 catch ( const Warning & /*warning_*/ )
148 {
149 // FIXME: need a way to report warnings in constructor
150 }
151 catch ( const Error & /*error_*/ )
152 {
153 // Release resources
154 delete _imgRef;
155 throw;
156 }
157}
158
159// Construct Image of specified size from in-memory BLOB
160Magick::Image::Image ( const Blob &blob_,
161 const Geometry &size_ )
162 : _imgRef(new ImageRef)
163{
164 try
165 {
166 // Read from Blob
167 read( blob_, size_ );
168 }
169 catch ( const Warning & /*warning_*/ )
170 {
171 // FIXME: need a way to report warnings in constructor
172 }
173 catch ( const Error & /*error_*/ )
174 {
175 // Release resources
176 delete _imgRef;
177 throw;
178 }
179}
180
181// Construct Image of specified size and depth from in-memory BLOB
182Magick::Image::Image ( const Blob &blob_,
183 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +0000184 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +0000185 : _imgRef(new ImageRef)
186{
187 try
188 {
189 // Read from Blob
190 read( blob_, size_, depth_ );
191 }
192 catch ( const Warning & /*warning_*/ )
193 {
194 // FIXME: need a way to report warnings in constructor
195 }
196 catch ( const Error & /*error_*/ )
197 {
198 // Release resources
199 delete _imgRef;
200 throw;
201 }
202}
203
204// Construct Image of specified size, depth, and format from in-memory BLOB
205Magick::Image::Image ( const Blob &blob_,
206 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +0000207 const size_t depth_,
cristy3ed852e2009-09-05 21:47:34 +0000208 const std::string &magick_ )
209 : _imgRef(new ImageRef)
210{
211 try
212 {
213 // Read from Blob
214 read( blob_, size_, depth_, magick_ );
215 }
216 catch ( const Warning & /*warning_*/ )
217 {
218 // FIXME: need a way to report warnings in constructor
219 }
220 catch ( const Error & /*error_*/ )
221 {
222 // Release resources
223 delete _imgRef;
224 throw;
225 }
226}
227
228// Construct Image of specified size, and format from in-memory BLOB
229Magick::Image::Image ( const Blob &blob_,
230 const Geometry &size_,
231 const std::string &magick_ )
232 : _imgRef(new ImageRef)
233{
234 try
235 {
236 // Read from Blob
237 read( blob_, size_, magick_ );
238 }
239 catch ( const Warning & /*warning_*/ )
240 {
241 // FIXME: need a way to report warnings in constructor
242 }
243 catch ( const Error & /*error_*/ )
244 {
245 // Release resources
246 delete _imgRef;
247 throw;
248 }
249}
250
251// Construct an image based on an array of raw pixels, of specified
252// type and mapping, in memory
cristyeaedf062010-05-29 22:36:02 +0000253Magick::Image::Image ( const size_t width_,
254 const size_t height_,
cristy3ed852e2009-09-05 21:47:34 +0000255 const std::string &map_,
256 const StorageType type_,
257 const void *pixels_ )
258 : _imgRef(new ImageRef)
259{
260 try
261 {
262 read( width_, height_, map_.c_str(), type_, pixels_ );
263 }
264 catch ( const Warning & /*warning_*/ )
265 {
266 // FIXME: need a way to report warnings in constructor
267 }
268 catch ( const Error & /*error_*/ )
269 {
270 // Release resources
271 delete _imgRef;
272 throw;
273 }
274}
275
276// Default constructor
277Magick::Image::Image( void )
278 : _imgRef(new ImageRef)
279{
280}
281
282// Destructor
283/* virtual */
284Magick::Image::~Image()
285{
286 bool doDelete = false;
287 {
288 Lock( &_imgRef->_mutexLock );
289 if ( --_imgRef->_refCount == 0 )
290 doDelete = true;
291 }
292
293 if ( doDelete )
294 {
295 delete _imgRef;
296 }
297 _imgRef = 0;
298}
299
300// Adaptive-blur image
301void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
302{
303 ExceptionInfo exceptionInfo;
304 GetExceptionInfo( &exceptionInfo );
305 MagickCore::Image* newImage =
306 AdaptiveBlurImage( image(), radius_, sigma_, &exceptionInfo);
307 replaceImage( newImage );
308 throwException( exceptionInfo );
309 (void) DestroyExceptionInfo( &exceptionInfo );
310}
311
312// Local adaptive threshold image
313// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
314// Width x height define the size of the pixel neighborhood
315// offset = constant to subtract from pixel neighborhood mean
cristyeaedf062010-05-29 22:36:02 +0000316void Magick::Image::adaptiveThreshold ( const size_t width_,
317 const size_t height_,
cristy4e0eef02010-05-30 21:52:21 +0000318 const ssize_t offset_ )
cristy3ed852e2009-09-05 21:47:34 +0000319{
320 ExceptionInfo exceptionInfo;
321 GetExceptionInfo( &exceptionInfo );
322 MagickCore::Image* newImage =
323 AdaptiveThresholdImage( constImage(), width_, height_, offset_, &exceptionInfo );
324 replaceImage( newImage );
325 throwException( exceptionInfo );
326 (void) DestroyExceptionInfo( &exceptionInfo );
327}
328
329// Add noise to image
330void Magick::Image::addNoise( const NoiseType noiseType_ )
331{
332 ExceptionInfo exceptionInfo;
333 GetExceptionInfo( &exceptionInfo );
334 MagickCore::Image* newImage =
335 AddNoiseImage ( image(),
336 noiseType_,
337 &exceptionInfo );
338 replaceImage( newImage );
339 throwException( exceptionInfo );
340 (void) DestroyExceptionInfo( &exceptionInfo );
341}
342
343void Magick::Image::addNoiseChannel( const ChannelType channel_,
344 const NoiseType noiseType_ )
345{
346 ExceptionInfo exceptionInfo;
347 GetExceptionInfo( &exceptionInfo );
cristy490408a2011-07-07 14:42:05 +0000348 PushPixelComponentMap( image(), channel_);
cristy3ed852e2009-09-05 21:47:34 +0000349 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +0000350 AddNoiseImage ( image(),
cristy3ed852e2009-09-05 21:47:34 +0000351 noiseType_,
352 &exceptionInfo );
cristy490408a2011-07-07 14:42:05 +0000353 PopPixelComponentMap( image() );
cristy3ed852e2009-09-05 21:47:34 +0000354 replaceImage( newImage );
355 throwException( exceptionInfo );
356 (void) DestroyExceptionInfo( &exceptionInfo );
357}
358
359// Affine Transform image
360void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
361{
362 ExceptionInfo exceptionInfo;
363 GetExceptionInfo( &exceptionInfo );
364
365 AffineMatrix _affine;
366 _affine.sx = affine_.sx();
367 _affine.sy = affine_.sy();
368 _affine.rx = affine_.rx();
369 _affine.ry = affine_.ry();
370 _affine.tx = affine_.tx();
371 _affine.ty = affine_.ty();
372
373 MagickCore::Image* newImage =
374 AffineTransformImage( image(), &_affine, &exceptionInfo);
375 replaceImage( newImage );
376 throwException( exceptionInfo );
377 (void) DestroyExceptionInfo( &exceptionInfo );
378}
379
380// Annotate using specified text, and placement location
381void Magick::Image::annotate ( const std::string &text_,
382 const Geometry &location_ )
383{
384 annotate ( text_, location_, NorthWestGravity, 0.0 );
385}
386// Annotate using specified text, bounding area, and placement gravity
387void Magick::Image::annotate ( const std::string &text_,
388 const Geometry &boundingArea_,
389 const GravityType gravity_ )
390{
391 annotate ( text_, boundingArea_, gravity_, 0.0 );
392}
393// Annotate with text using specified text, bounding area, placement
394// gravity, and rotation.
395void Magick::Image::annotate ( const std::string &text_,
396 const Geometry &boundingArea_,
397 const GravityType gravity_,
398 const double degrees_ )
399{
400 modifyImage();
401
402 DrawInfo *drawInfo
403 = options()->drawInfo();
404
405 drawInfo->text = const_cast<char *>(text_.c_str());
406
407 char boundingArea[MaxTextExtent];
408
409 drawInfo->geometry = 0;
410 if ( boundingArea_.isValid() ){
411 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
412 {
cristyb51dff52011-05-19 16:55:47 +0000413 FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
cristyfe0019b2010-06-07 02:23:32 +0000414 (double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
cristy3ed852e2009-09-05 21:47:34 +0000415 }
416 else
417 {
418 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
419 MaxTextExtent);
420 }
421 drawInfo->geometry = boundingArea;
422 }
423
424 drawInfo->gravity = gravity_;
425
426 AffineMatrix oaffine = drawInfo->affine;
427 if ( degrees_ != 0.0)
428 {
429 AffineMatrix affine;
430 affine.sx=1.0;
431 affine.rx=0.0;
432 affine.ry=0.0;
433 affine.sy=1.0;
434 affine.tx=0.0;
435 affine.ty=0.0;
436
437 AffineMatrix current = drawInfo->affine;
438 affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
439 affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
440 affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
441 affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
442
443 drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
444 drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
445 drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
446 drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
447 drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
448 +current.tx;
449 }
450
451 AnnotateImage( image(), drawInfo );
452
453 // Restore original values
454 drawInfo->affine = oaffine;
455 drawInfo->text = 0;
456 drawInfo->geometry = 0;
457
458 throwImageException();
459}
460// Annotate with text (bounding area is entire image) and placement gravity.
461void Magick::Image::annotate ( const std::string &text_,
462 const GravityType gravity_ )
463{
464 modifyImage();
465
466 DrawInfo *drawInfo
467 = options()->drawInfo();
468
469 drawInfo->text = const_cast<char *>(text_.c_str());
470
471 drawInfo->gravity = gravity_;
472
473 AnnotateImage( image(), drawInfo );
474
475 drawInfo->gravity = NorthWestGravity;
476 drawInfo->text = 0;
477
478 throwImageException();
479}
480
481// Blur image
482void Magick::Image::blur( const double radius_, const double sigma_ )
483{
484 ExceptionInfo exceptionInfo;
485 GetExceptionInfo( &exceptionInfo );
486 MagickCore::Image* newImage =
487 BlurImage( image(), radius_, sigma_, &exceptionInfo);
488 replaceImage( newImage );
489 throwException( exceptionInfo );
490 (void) DestroyExceptionInfo( &exceptionInfo );
491}
492
493void Magick::Image::blurChannel( const ChannelType channel_,
494 const double radius_, const double sigma_ )
495{
496 ExceptionInfo exceptionInfo;
497 GetExceptionInfo( &exceptionInfo );
498 MagickCore::Image* newImage =
499 BlurImageChannel( image(), channel_,radius_, sigma_, &exceptionInfo);
500 replaceImage( newImage );
501 throwException( exceptionInfo );
502 (void) DestroyExceptionInfo( &exceptionInfo );
503}
504
505// Add border to image
506// Only uses width & height
507void Magick::Image::border( const Geometry &geometry_ )
508{
509 RectangleInfo borderInfo = geometry_;
510 ExceptionInfo exceptionInfo;
511 GetExceptionInfo( &exceptionInfo );
512 MagickCore::Image* newImage =
513 BorderImage( image(), &borderInfo, &exceptionInfo);
514 replaceImage( newImage );
515 throwException( exceptionInfo );
516 (void) DestroyExceptionInfo( &exceptionInfo );
517}
518
519// Extract channel from image
520void Magick::Image::channel ( const ChannelType channel_ )
521{
522 modifyImage();
523 SeparateImageChannel ( image(), channel_ );
524 throwImageException();
525}
526
527// Set or obtain modulus channel depth
cristyfefab1b2011-07-05 00:33:22 +0000528void Magick::Image::channelDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +0000529{
530 modifyImage();
cristyfefab1b2011-07-05 00:33:22 +0000531 SetImageDepth( image(), depth_);
cristy3ed852e2009-09-05 21:47:34 +0000532 throwImageException();
533}
cristyfefab1b2011-07-05 00:33:22 +0000534size_t Magick::Image::channelDepth ( )
cristy3ed852e2009-09-05 21:47:34 +0000535{
cristyeaedf062010-05-29 22:36:02 +0000536 size_t channel_depth;
cristy3ed852e2009-09-05 21:47:34 +0000537
538 ExceptionInfo exceptionInfo;
539 GetExceptionInfo( &exceptionInfo );
cristyfefab1b2011-07-05 00:33:22 +0000540 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000541 throwException( exceptionInfo );
542 (void) DestroyExceptionInfo( &exceptionInfo );
543 return channel_depth;
544}
545
546
547// Charcoal-effect image
548void Magick::Image::charcoal( const double radius_, const double sigma_ )
549{
550 ExceptionInfo exceptionInfo;
551 GetExceptionInfo( &exceptionInfo );
552 MagickCore::Image* newImage =
553 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
554 replaceImage( newImage );
555 throwException( exceptionInfo );
556 (void) DestroyExceptionInfo( &exceptionInfo );
557}
558
559// Chop image
560void Magick::Image::chop( const Geometry &geometry_ )
561{
562 RectangleInfo chopInfo = geometry_;
563 ExceptionInfo exceptionInfo;
564 GetExceptionInfo( &exceptionInfo );
565 MagickCore::Image* newImage =
566 ChopImage( image(), &chopInfo, &exceptionInfo);
567 replaceImage( newImage );
568 throwException( exceptionInfo );
569 (void) DestroyExceptionInfo( &exceptionInfo );
570}
571
cristyb32b90a2009-09-07 21:45:48 +0000572// contains one or more color corrections and applies the correction to the
573// image.
574void Magick::Image::cdl ( const std::string &cdl_ )
575{
576 modifyImage();
577 (void) ColorDecisionListImage( image(), cdl_.c_str() );
578 throwImageException();
579}
580
cristy3ed852e2009-09-05 21:47:34 +0000581// Colorize
cristy4c08aed2011-07-01 19:47:50 +0000582void Magick::Image::colorize ( const unsigned int alphaRed_,
583 const unsigned int alphaGreen_,
584 const unsigned int alphaBlue_,
cristy3ed852e2009-09-05 21:47:34 +0000585 const Color &penColor_ )
586{
587 if ( !penColor_.isValid() )
588 {
589 throwExceptionExplicit( OptionError,
590 "Pen color argument is invalid");
591 }
592
cristy4c08aed2011-07-01 19:47:50 +0000593 char alpha[MaxTextExtent];
594 FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
cristy3ed852e2009-09-05 21:47:34 +0000595
596 ExceptionInfo exceptionInfo;
597 GetExceptionInfo( &exceptionInfo );
598 MagickCore::Image* newImage =
cristy4c08aed2011-07-01 19:47:50 +0000599 ColorizeImage ( image(), alpha,
cristy3ed852e2009-09-05 21:47:34 +0000600 penColor_, &exceptionInfo );
601 replaceImage( newImage );
602 throwException( exceptionInfo );
603 (void) DestroyExceptionInfo( &exceptionInfo );
604}
cristy4c08aed2011-07-01 19:47:50 +0000605void Magick::Image::colorize ( const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000606 const Color &penColor_ )
607{
cristy4c08aed2011-07-01 19:47:50 +0000608 colorize( alpha_, alpha_, alpha_, penColor_ );
cristy3ed852e2009-09-05 21:47:34 +0000609}
610
cristy735e8942010-04-02 20:32:57 +0000611// Apply a color matrix to the image channels. The user supplied
612// matrix may be of order 1 to 6 (1x1 through 6x6).
cristyeaedf062010-05-29 22:36:02 +0000613void Magick::Image::colorMatrix (const size_t order_,
cristyc8918bb2010-04-03 01:57:27 +0000614 const double *color_matrix_)
cristy735e8942010-04-02 20:32:57 +0000615{
cristyc8918bb2010-04-03 01:57:27 +0000616 KernelInfo
617 *kernel_info;
618
cristy735e8942010-04-02 20:32:57 +0000619 ExceptionInfo exceptionInfo;
620 GetExceptionInfo( &exceptionInfo );
cristyc8918bb2010-04-03 01:57:27 +0000621 kernel_info=AcquireKernelInfo("1");
622 kernel_info->width=order_;
623 kernel_info->height=order_;
cristyc8918bb2010-04-03 01:57:27 +0000624 kernel_info->values=(double *) color_matrix_;
cristy735e8942010-04-02 20:32:57 +0000625 MagickCore::Image* newImage =
cristyc8918bb2010-04-03 01:57:27 +0000626 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
cristya2175d32010-04-03 02:25:17 +0000627 kernel_info->values=(double *) NULL;
cristyc8918bb2010-04-03 01:57:27 +0000628 kernel_info=DestroyKernelInfo(kernel_info);
cristy735e8942010-04-02 20:32:57 +0000629 replaceImage( newImage );
630 throwException( exceptionInfo );
631 (void) DestroyExceptionInfo( &exceptionInfo );
632}
633
cristy3ed852e2009-09-05 21:47:34 +0000634// Compare current image with another image
635// Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
636// in the current image. False is returned if the images are identical.
637bool Magick::Image::compare ( const Image &reference_ )
638{
639 modifyImage();
640 Image ref = reference_;
641 ref.modifyImage();
642 return static_cast<bool>(IsImagesEqual(image(), ref.image()));
643}
644
645// Composite two images
646void Magick::Image::composite ( const Image &compositeImage_,
cristyd99b0962010-05-29 23:14:26 +0000647 const ssize_t xOffset_,
648 const ssize_t yOffset_,
cristy3ed852e2009-09-05 21:47:34 +0000649 const CompositeOperator compose_ )
650{
651 // Image supplied as compositeImage is composited with current image and
652 // results in updating current image.
653 modifyImage();
654
655 CompositeImage( image(),
656 compose_,
657 compositeImage_.constImage(),
658 xOffset_,
659 yOffset_ );
660 throwImageException();
661}
662void Magick::Image::composite ( const Image &compositeImage_,
663 const Geometry &offset_,
664 const CompositeOperator compose_ )
665{
666 modifyImage();
667
cristybb503372010-05-27 20:51:26 +0000668 ssize_t x = offset_.xOff();
669 ssize_t y = offset_.yOff();
670 size_t width = columns();
671 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +0000672
673 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
674 &x, &y,
675 &width, &height );
676
677 CompositeImage( image(),
678 compose_,
679 compositeImage_.constImage(),
680 x, y );
681 throwImageException();
682}
683void Magick::Image::composite ( const Image &compositeImage_,
684 const GravityType gravity_,
685 const CompositeOperator compose_ )
686{
687 modifyImage();
688
689 RectangleInfo geometry;
690
691 SetGeometry(compositeImage_.constImage(), &geometry);
692 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
693
694 CompositeImage( image(),
695 compose_,
696 compositeImage_.constImage(),
697 geometry.x, geometry.y );
698 throwImageException();
699}
700
701// Contrast image
cristyeaedf062010-05-29 22:36:02 +0000702void Magick::Image::contrast ( const size_t sharpen_ )
cristy3ed852e2009-09-05 21:47:34 +0000703{
704 modifyImage();
705 ContrastImage ( image(), (MagickBooleanType) sharpen_ );
706 throwImageException();
707}
708
709// Convolve image. Applies a general image convolution kernel to the image.
710// order_ represents the number of columns and rows in the filter kernel.
711// kernel_ is an array of doubles representing the convolution kernel.
cristyeaedf062010-05-29 22:36:02 +0000712void Magick::Image::convolve ( const size_t order_,
cristy3ed852e2009-09-05 21:47:34 +0000713 const double *kernel_ )
714{
715 ExceptionInfo exceptionInfo;
716 GetExceptionInfo( &exceptionInfo );
717 MagickCore::Image* newImage =
718 ConvolveImage ( image(), order_,
719 kernel_, &exceptionInfo );
720 replaceImage( newImage );
721 throwException( exceptionInfo );
722 (void) DestroyExceptionInfo( &exceptionInfo );
723}
724
725// Crop image
726void Magick::Image::crop ( const Geometry &geometry_ )
727{
728 RectangleInfo cropInfo = geometry_;
729 ExceptionInfo exceptionInfo;
730 GetExceptionInfo( &exceptionInfo );
731 MagickCore::Image* newImage =
732 CropImage( image(),
733 &cropInfo,
734 &exceptionInfo);
735 replaceImage( newImage );
736 throwException( exceptionInfo );
737 (void) DestroyExceptionInfo( &exceptionInfo );
738}
739
740// Cycle Color Map
cristyd99b0962010-05-29 23:14:26 +0000741void Magick::Image::cycleColormap ( const ssize_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +0000742{
743 modifyImage();
744 CycleColormapImage( image(), amount_ );
745 throwImageException();
746}
747
748// Despeckle
749void Magick::Image::despeckle ( void )
750{
751 ExceptionInfo exceptionInfo;
752 GetExceptionInfo( &exceptionInfo );
753 MagickCore::Image* newImage =
754 DespeckleImage( image(), &exceptionInfo );
755 replaceImage( newImage );
756 throwException( exceptionInfo );
757 (void) DestroyExceptionInfo( &exceptionInfo );
758}
759
760// Display image
761void Magick::Image::display( void )
762{
763 DisplayImages( imageInfo(), image() );
764}
765
766// Distort image. distorts an image using various distortion methods, by
767// mapping color lookups of the source image to a new destination image
768// usally of the same size as the source image, unless 'bestfit' is set to
769// true.
cristyb32b90a2009-09-07 21:45:48 +0000770void Magick::Image::distort ( const DistortImageMethod method_,
cristybb503372010-05-27 20:51:26 +0000771 const size_t number_arguments_,
cristyb32b90a2009-09-07 21:45:48 +0000772 const double *arguments_,
773 const bool bestfit_ )
cristy3ed852e2009-09-05 21:47:34 +0000774{
775 ExceptionInfo exceptionInfo;
776 GetExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +0000777 MagickCore::Image* newImage = DistortImage ( image(), method_,
778 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
779 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000780 replaceImage( newImage );
781 throwException( exceptionInfo );
782 (void) DestroyExceptionInfo( &exceptionInfo );
783}
784
785// Draw on image using single drawable
786void Magick::Image::draw ( const Magick::Drawable &drawable_ )
787{
788 modifyImage();
789
790 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
791
792 if(wand)
793 {
794 drawable_.operator()(wand);
795
796 if( constImage()->exception.severity == UndefinedException)
797 DrawRender(wand);
798
799 wand=DestroyDrawingWand(wand);
800 }
801
802 throwImageException();
803}
804
805// Draw on image using a drawable list
806void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
807{
808 modifyImage();
809
810 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
811
812 if(wand)
813 {
814 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
815 p != drawable_.end(); p++ )
816 {
817 p->operator()(wand);
818 if( constImage()->exception.severity != UndefinedException)
819 break;
820 }
821
822 if( constImage()->exception.severity == UndefinedException)
823 DrawRender(wand);
824
825 wand=DestroyDrawingWand(wand);
826 }
827
828 throwImageException();
829}
830
831// Hilight edges in image
832void Magick::Image::edge ( const double radius_ )
833{
834 ExceptionInfo exceptionInfo;
835 GetExceptionInfo( &exceptionInfo );
836 MagickCore::Image* newImage =
837 EdgeImage( image(), radius_, &exceptionInfo );
838 replaceImage( newImage );
839 throwException( exceptionInfo );
840 (void) DestroyExceptionInfo( &exceptionInfo );
841}
842
843// Emboss image (hilight edges)
844void Magick::Image::emboss ( const double radius_, const double sigma_ )
845{
846 ExceptionInfo exceptionInfo;
847 GetExceptionInfo( &exceptionInfo );
848 MagickCore::Image* newImage =
849 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
850 replaceImage( newImage );
851 throwException( exceptionInfo );
852 (void) DestroyExceptionInfo( &exceptionInfo );
853}
854
855// Enhance image (minimize noise)
856void Magick::Image::enhance ( void )
857{
858 ExceptionInfo exceptionInfo;
859 GetExceptionInfo( &exceptionInfo );
860 MagickCore::Image* newImage =
861 EnhanceImage( image(), &exceptionInfo );
862 replaceImage( newImage );
863 throwException( exceptionInfo );
864 (void) DestroyExceptionInfo( &exceptionInfo );
865}
866
867// Equalize image (histogram equalization)
868void Magick::Image::equalize ( void )
869{
870 modifyImage();
871 EqualizeImage( image() );
872 throwImageException();
873}
874
875// Erase image to current "background color"
876void Magick::Image::erase ( void )
877{
878 modifyImage();
879 SetImageBackgroundColor( image() );
880 throwImageException();
881}
882
883// Extends image as defined by the geometry.
884//
885void Magick::Image::extent ( const Geometry &geometry_ )
886{
887 RectangleInfo extentInfo = geometry_;
888 modifyImage();
cristy8bf9e292010-02-21 17:48:01 +0000889 ExceptionInfo exceptionInfo;
890 GetExceptionInfo( &exceptionInfo );
cristy1ee42c42010-05-12 12:52:50 +0000891 MagickCore::Image* newImage =
892 ExtentImage ( image(), &extentInfo, &exceptionInfo );
893 replaceImage( newImage );
cristy8bf9e292010-02-21 17:48:01 +0000894 throwException( exceptionInfo );
895 (void) DestroyExceptionInfo( &exceptionInfo );
896}
897void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
898{
899 backgroundColor ( backgroundColor_ );
900 extent ( geometry_ );
901}
cristyff024b42010-02-21 22:55:09 +0000902void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
cristy8bf9e292010-02-21 17:48:01 +0000903{
904 image()->gravity = gravity_;
905 extent ( geometry_ );
906}
907void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
908{
909 image()->gravity = gravity_;
910 backgroundColor ( backgroundColor_ );
911 extent ( geometry_ );
cristy3ed852e2009-09-05 21:47:34 +0000912}
913
914// Flip image (reflect each scanline in the vertical direction)
915void Magick::Image::flip ( void )
916{
917 ExceptionInfo exceptionInfo;
918 GetExceptionInfo( &exceptionInfo );
919 MagickCore::Image* newImage =
920 FlipImage( image(), &exceptionInfo );
921 replaceImage( newImage );
922 throwException( exceptionInfo );
923 (void) DestroyExceptionInfo( &exceptionInfo );
924}
925
926// Flood-fill color across pixels that match the color of the
927// target pixel and are neighbors of the target pixel.
928// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000929void Magick::Image::floodFillColor( const ssize_t x_,
930 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000931 const Magick::Color &fillColor_ )
932{
933 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
934}
935void Magick::Image::floodFillColor( const Geometry &point_,
936 const Magick::Color &fillColor_ )
937{
938 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
939}
940
941// Flood-fill color across pixels starting at target-pixel and
942// stopping at pixels matching specified border color.
943// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000944void Magick::Image::floodFillColor( const ssize_t x_,
945 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000946 const Magick::Color &fillColor_,
947 const Magick::Color &borderColor_ )
948{
949 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
950 borderColor_ );
951}
952void Magick::Image::floodFillColor( const Geometry &point_,
953 const Magick::Color &fillColor_,
954 const Magick::Color &borderColor_ )
955{
956 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
957 borderColor_ );
958}
959
960// Floodfill pixels matching color (within fuzz factor) of target
cristy4c08aed2011-07-01 19:47:50 +0000961// pixel(x,y) with replacement alpha value using method.
cristy35ef8242010-06-03 16:24:13 +0000962void Magick::Image::floodFillOpacity( const ssize_t x_,
963 const ssize_t y_,
cristy4c08aed2011-07-01 19:47:50 +0000964 const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000965 const PaintMethod method_ )
966{
967 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +0000968 PixelInfo target;
969 GetPixelInfo(image(),&target);
cristy3ed852e2009-09-05 21:47:34 +0000970 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
971 target.red=pixel.red;
972 target.green=pixel.green;
973 target.blue=pixel.blue;
cristy4c08aed2011-07-01 19:47:50 +0000974 target.alpha=alpha_;
cristy3ed852e2009-09-05 21:47:34 +0000975 FloodfillPaintImage ( image(),
976 DefaultChannels,
977 options()->drawInfo(), // const DrawInfo *draw_info
978 &target,
cristybb503372010-05-27 20:51:26 +0000979 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +0000980 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
981 throwImageException();
982}
983
984// Flood-fill texture across pixels that match the color of the
985// target pixel and are neighbors of the target pixel.
986// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000987void Magick::Image::floodFillTexture( const ssize_t x_,
988 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000989 const Magick::Image &texture_ )
990{
991 modifyImage();
992
993 // Set drawing pattern
994 options()->fillPattern(texture_.constImage());
995
996 // Get pixel view
997 Pixels pixels(*this);
998 // Fill image
cristy4c08aed2011-07-01 19:47:50 +0000999 Quantum *p = pixels.get(x_, y_, 1, 1 );
1000 PixelInfo target;
1001 GetPixelInfo(constImage(),&target);
1002 target.red=GetPixelRed(constImage(),p);
1003 target.green=GetPixelGreen(constImage(),p);
1004 target.blue=GetPixelBlue(constImage(),p);
cristy3ed852e2009-09-05 21:47:34 +00001005 if (p)
1006 FloodfillPaintImage ( image(), // Image *image
1007 DefaultChannels,
1008 options()->drawInfo(), // const DrawInfo *draw_info
1009 &target, // const MagickPacket target
cristybb503372010-05-27 20:51:26 +00001010 static_cast<ssize_t>(x_), // const ssize_t x_offset
1011 static_cast<ssize_t>(y_), // const ssize_t y_offset
cristy3ed852e2009-09-05 21:47:34 +00001012 MagickFalse // const PaintMethod method
1013 );
1014
1015 throwImageException();
1016}
1017void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1018 const Magick::Image &texture_ )
1019{
1020 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1021}
1022
1023// Flood-fill texture across pixels starting at target-pixel and
1024// stopping at pixels matching specified border color.
1025// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +00001026void Magick::Image::floodFillTexture( const ssize_t x_,
1027 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001028 const Magick::Image &texture_,
1029 const Magick::Color &borderColor_ )
1030{
1031 modifyImage();
1032
1033 // Set drawing fill pattern
1034 options()->fillPattern(texture_.constImage());
1035
cristy4c08aed2011-07-01 19:47:50 +00001036 PixelInfo target;
1037 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001038 target.red=static_cast<PixelPacket>(borderColor_).red;
1039 target.green=static_cast<PixelPacket>(borderColor_).green;
1040 target.blue=static_cast<PixelPacket>(borderColor_).blue;
1041 FloodfillPaintImage ( image(),
1042 DefaultChannels,
1043 options()->drawInfo(),
1044 &target,
cristybb503372010-05-27 20:51:26 +00001045 static_cast<ssize_t>(x_),
1046 static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +00001047 MagickTrue);
1048
1049 throwImageException();
1050}
1051void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1052 const Magick::Image &texture_,
1053 const Magick::Color &borderColor_ )
1054{
1055 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1056}
1057
1058// Flop image (reflect each scanline in the horizontal direction)
1059void Magick::Image::flop ( void )
1060{
1061 ExceptionInfo exceptionInfo;
1062 GetExceptionInfo( &exceptionInfo );
1063 MagickCore::Image* newImage =
1064 FlopImage( image(), &exceptionInfo );
1065 replaceImage( newImage );
1066 throwException( exceptionInfo );
1067 (void) DestroyExceptionInfo( &exceptionInfo );
1068}
1069
1070// Frame image
1071void Magick::Image::frame ( const Geometry &geometry_ )
1072{
1073 FrameInfo info;
1074
cristybb503372010-05-27 20:51:26 +00001075 info.x = static_cast<ssize_t>(geometry_.width());
1076 info.y = static_cast<ssize_t>(geometry_.height());
1077 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1078 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
cristy3ed852e2009-09-05 21:47:34 +00001079 info.outer_bevel = geometry_.xOff();
1080 info.inner_bevel = geometry_.yOff();
1081
1082 ExceptionInfo exceptionInfo;
1083 GetExceptionInfo( &exceptionInfo );
1084 MagickCore::Image* newImage =
1085 FrameImage( image(), &info, &exceptionInfo );
1086 replaceImage( newImage );
1087 throwException( exceptionInfo );
1088 (void) DestroyExceptionInfo( &exceptionInfo );
1089}
cristyeaedf062010-05-29 22:36:02 +00001090void Magick::Image::frame ( const size_t width_,
1091 const size_t height_,
cristyd99b0962010-05-29 23:14:26 +00001092 const ssize_t outerBevel_, const ssize_t innerBevel_ )
cristy3ed852e2009-09-05 21:47:34 +00001093{
1094 FrameInfo info;
cristybb503372010-05-27 20:51:26 +00001095 info.x = static_cast<ssize_t>(width_);
1096 info.y = static_cast<ssize_t>(height_);
1097 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1098 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1099 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1100 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
cristy3ed852e2009-09-05 21:47:34 +00001101
1102 ExceptionInfo exceptionInfo;
1103 GetExceptionInfo( &exceptionInfo );
1104 MagickCore::Image* newImage =
1105 FrameImage( image(), &info, &exceptionInfo );
1106 replaceImage( newImage );
1107 throwException( exceptionInfo );
1108 (void) DestroyExceptionInfo( &exceptionInfo );
1109}
1110
cristyc9550792009-11-13 20:05:42 +00001111// Fx image. Applies a mathematical expression to the image.
1112void Magick::Image::fx ( const std::string expression )
1113{
1114 ExceptionInfo exceptionInfo;
1115 GetExceptionInfo( &exceptionInfo );
1116 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001117 FxImage ( image(), expression.c_str(), &exceptionInfo );
cristyc9550792009-11-13 20:05:42 +00001118 replaceImage( newImage );
1119 throwException( exceptionInfo );
1120 (void) DestroyExceptionInfo( &exceptionInfo );
1121}
cristy3ed852e2009-09-05 21:47:34 +00001122void Magick::Image::fx ( const std::string expression,
1123 const Magick::ChannelType channel )
1124{
1125 ExceptionInfo exceptionInfo;
1126 GetExceptionInfo( &exceptionInfo );
cristy490408a2011-07-07 14:42:05 +00001127 PushPixelComponentMap( image(), channel );
cristy3ed852e2009-09-05 21:47:34 +00001128 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001129 FxImage ( image(), expression.c_str(), &exceptionInfo );
1130 PopPixelComponentMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001131 replaceImage( newImage );
1132 throwException( exceptionInfo );
1133 (void) DestroyExceptionInfo( &exceptionInfo );
1134}
1135
1136// Gamma correct image
1137void Magick::Image::gamma ( const double gamma_ )
1138{
cristy3ed852e2009-09-05 21:47:34 +00001139 modifyImage();
cristy50fbc382011-07-07 02:19:17 +00001140 GammaImage ( image(), gamma_ );
cristy3ed852e2009-09-05 21:47:34 +00001141}
1142
1143void Magick::Image::gamma ( const double gammaRed_,
1144 const double gammaGreen_,
1145 const double gammaBlue_ )
1146{
1147 char gamma[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001148 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
cristy3ed852e2009-09-05 21:47:34 +00001149 gammaRed_, gammaGreen_, gammaBlue_);
1150
1151 modifyImage();
cristy50fbc382011-07-07 02:19:17 +00001152 GammaImage ( image(), atof(gamma) );
cristy3ed852e2009-09-05 21:47:34 +00001153 throwImageException();
1154}
1155
1156// Gaussian blur image
1157// The number of neighbor pixels to be included in the convolution
1158// mask is specified by 'width_'. The standard deviation of the
1159// gaussian bell curve is specified by 'sigma_'.
1160void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1161{
1162 ExceptionInfo exceptionInfo;
1163 GetExceptionInfo( &exceptionInfo );
1164 MagickCore::Image* newImage =
1165 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1166 replaceImage( newImage );
1167 throwException( exceptionInfo );
1168 (void) DestroyExceptionInfo( &exceptionInfo );
1169}
1170
1171void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1172 const double width_,
1173 const double sigma_ )
1174{
1175 ExceptionInfo exceptionInfo;
1176 GetExceptionInfo( &exceptionInfo );
1177 MagickCore::Image* newImage =
1178 GaussianBlurImageChannel( image(), channel_, width_, sigma_, &exceptionInfo );
1179 replaceImage( newImage );
1180 throwException( exceptionInfo );
1181 (void) DestroyExceptionInfo( &exceptionInfo );
1182}
1183
cristyb32b90a2009-09-07 21:45:48 +00001184// Apply a color lookup table (Hald CLUT) to the image.
1185void Magick::Image::haldClut ( const Image &clutImage_ )
1186{
1187 modifyImage();
1188 (void) HaldClutImage( image(), clutImage_.constImage() );
1189 throwImageException();
1190}
1191
cristy3ed852e2009-09-05 21:47:34 +00001192// Implode image
1193void Magick::Image::implode ( const double factor_ )
1194{
1195 ExceptionInfo exceptionInfo;
1196 GetExceptionInfo( &exceptionInfo );
1197 MagickCore::Image* newImage =
1198 ImplodeImage( image(), factor_, &exceptionInfo );
1199 replaceImage( newImage );
1200 throwException( exceptionInfo );
1201 (void) DestroyExceptionInfo( &exceptionInfo );
1202}
1203
cristy529fcc22009-11-14 18:15:08 +00001204// implements the inverse discrete Fourier transform (IFT) of the image either
1205// as a magnitude / phase or real / imaginary image pair.
1206void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1207{
1208 ExceptionInfo exceptionInfo;
1209 GetExceptionInfo( &exceptionInfo );
1210 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1211 phase_.constImage(), MagickTrue, &exceptionInfo);
1212 replaceImage( newImage );
1213 throwException( exceptionInfo );
1214 (void) DestroyExceptionInfo( &exceptionInfo );
1215}
1216void Magick::Image::inverseFourierTransform ( const Image &phase_,
1217 const bool magnitude_ )
1218{
1219 ExceptionInfo exceptionInfo;
1220 GetExceptionInfo( &exceptionInfo );
1221 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1222 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1223 &exceptionInfo);
1224 replaceImage( newImage );
1225 throwException( exceptionInfo );
1226 (void) DestroyExceptionInfo( &exceptionInfo );
1227}
1228
cristy3ed852e2009-09-05 21:47:34 +00001229// Level image. Adjust the levels of the image by scaling the colors
1230// falling between specified white and black points to the full
1231// available quantum range. The parameters provided represent the
1232// black, mid (gamma), and white points. The black point specifies
1233// the darkest color in the image. Colors darker than the black point
1234// are set to zero. Mid point (gamma) specifies a gamma correction to
1235// apply to the image. White point specifies the lightest color in the
1236// image. Colors brighter than the white point are set to the maximum
1237// quantum value. The black and white point have the valid range 0 to
1238// QuantumRange while gamma has a useful range of 0 to ten.
1239void Magick::Image::level ( const double black_point,
1240 const double white_point,
1241 const double gamma )
1242{
1243 modifyImage();
cristyf89cb1d2011-07-07 01:24:37 +00001244 (void) LevelImage( image(), black_point, white_point, gamma );
cristy3ed852e2009-09-05 21:47:34 +00001245 throwImageException();
1246}
1247
1248// Magnify image by integral size
1249void Magick::Image::magnify ( void )
1250{
1251 ExceptionInfo exceptionInfo;
1252 GetExceptionInfo( &exceptionInfo );
1253 MagickCore::Image* newImage =
1254 MagnifyImage( image(), &exceptionInfo );
1255 replaceImage( newImage );
1256 throwException( exceptionInfo );
1257 (void) DestroyExceptionInfo( &exceptionInfo );
1258}
1259
1260// Remap image colors with closest color from reference image
1261void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1262{
1263 modifyImage();
1264 options()->quantizeDither( dither_ );
1265 RemapImage ( options()->quantizeInfo(), image(),
1266 mapImage_.constImage());
1267 throwImageException();
1268}
cristy4c08aed2011-07-01 19:47:50 +00001269// Floodfill designated area with replacement alpha value
cristy3ed852e2009-09-05 21:47:34 +00001270void Magick::Image::matteFloodfill ( const Color &target_ ,
cristy4c08aed2011-07-01 19:47:50 +00001271 const unsigned int alpha_,
cristyd99b0962010-05-29 23:14:26 +00001272 const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001273 const Magick::PaintMethod method_ )
1274{
1275 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001276 PixelInfo target;
1277 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001278 target.red=static_cast<PixelPacket>(target_).red;
1279 target.green=static_cast<PixelPacket>(target_).green;
1280 target.blue=static_cast<PixelPacket>(target_).blue;
cristy4c08aed2011-07-01 19:47:50 +00001281 target.alpha=alpha_;
cristy3ed852e2009-09-05 21:47:34 +00001282 FloodfillPaintImage ( image(), OpacityChannel, options()->drawInfo(), &target,
1283 x_, y_, method_ == FloodfillMethod ? MagickFalse : MagickTrue);
1284 throwImageException();
1285}
1286
1287// Filter image by replacing each pixel component with the median
1288// color in a circular neighborhood
1289void Magick::Image::medianFilter ( const double radius_ )
1290{
1291 ExceptionInfo exceptionInfo;
1292 GetExceptionInfo( &exceptionInfo );
1293 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001294 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1295 radius_,&exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001296 replaceImage( newImage );
1297 throwException( exceptionInfo );
1298 (void) DestroyExceptionInfo( &exceptionInfo );
1299}
1300
1301// Reduce image by integral size
1302void Magick::Image::minify ( void )
1303{
1304 ExceptionInfo exceptionInfo;
1305 GetExceptionInfo( &exceptionInfo );
1306 MagickCore::Image* newImage =
1307 MinifyImage( image(), &exceptionInfo );
1308 replaceImage( newImage );
1309 throwException( exceptionInfo );
1310 (void) DestroyExceptionInfo( &exceptionInfo );
1311}
1312
1313// Modulate percent hue, saturation, and brightness of an image
1314void Magick::Image::modulate ( const double brightness_,
1315 const double saturation_,
1316 const double hue_ )
1317{
1318 char modulate[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001319 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
cristy3ed852e2009-09-05 21:47:34 +00001320 brightness_, saturation_, hue_);
1321
1322 modifyImage();
1323 ModulateImage( image(), modulate );
1324 throwImageException();
1325}
1326
1327// Motion blur image with specified blur factor
1328// The radius_ parameter specifies the radius of the Gaussian, in
1329// pixels, not counting the center pixel. The sigma_ parameter
1330// specifies the standard deviation of the Laplacian, in pixels.
1331// The angle_ parameter specifies the angle the object appears
1332// to be comming from (zero degrees is from the right).
1333void Magick::Image::motionBlur ( const double radius_,
1334 const double sigma_,
1335 const double angle_ )
1336{
1337 ExceptionInfo exceptionInfo;
1338 GetExceptionInfo( &exceptionInfo );
1339 MagickCore::Image* newImage =
1340 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1341 replaceImage( newImage );
1342 throwException( exceptionInfo );
1343 (void) DestroyExceptionInfo( &exceptionInfo );
1344}
1345
1346// Negate image. Set grayscale_ to true to effect grayscale values
1347// only
1348void Magick::Image::negate ( const bool grayscale_ )
1349{
1350 modifyImage();
1351 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse );
1352 throwImageException();
1353}
1354
1355// Normalize image
1356void Magick::Image::normalize ( void )
1357{
1358 modifyImage();
1359 NormalizeImage ( image() );
1360 throwImageException();
1361}
1362
1363// Oilpaint image
1364void Magick::Image::oilPaint ( const double radius_ )
1365{
1366 ExceptionInfo exceptionInfo;
1367 GetExceptionInfo( &exceptionInfo );
1368 MagickCore::Image* newImage =
1369 OilPaintImage( image(), radius_, &exceptionInfo );
1370 replaceImage( newImage );
1371 throwException( exceptionInfo );
1372 (void) DestroyExceptionInfo( &exceptionInfo );
1373}
1374
cristy4c08aed2011-07-01 19:47:50 +00001375// Set or attenuate the alpha channel. If the image pixels are
1376// opaque then they are set to the specified alpha value, otherwise
1377// they are blended with the supplied alpha value. The value of
1378// alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1379// OpaqueAlpha and TransparentAlpha are available to specify
cristy3ed852e2009-09-05 21:47:34 +00001380// completely opaque or completely transparent, respectively.
cristy4c08aed2011-07-01 19:47:50 +00001381void Magick::Image::alpha ( const unsigned int alpha_ )
cristy3ed852e2009-09-05 21:47:34 +00001382{
1383 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001384 SetImageOpacity( image(), alpha_ );
cristy3ed852e2009-09-05 21:47:34 +00001385}
1386
1387// Change the color of an opaque pixel to the pen color.
1388void Magick::Image::opaque ( const Color &opaqueColor_,
1389 const Color &penColor_ )
1390{
1391 if ( !opaqueColor_.isValid() )
1392 {
1393 throwExceptionExplicit( OptionError,
1394 "Opaque color argument is invalid" );
1395 }
1396 if ( !penColor_.isValid() )
1397 {
1398 throwExceptionExplicit( OptionError,
1399 "Pen color argument is invalid" );
1400 }
1401
1402 modifyImage();
1403 std::string opaqueColor = opaqueColor_;
1404 std::string penColor = penColor_;
1405
cristy4c08aed2011-07-01 19:47:50 +00001406 PixelInfo opaque;
1407 PixelInfo pen;
cristy3ed852e2009-09-05 21:47:34 +00001408 (void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque,&image()->exception);
1409 (void) QueryMagickColor(std::string(penColor_).c_str(),&pen,&image()->exception);
1410 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse );
1411 throwImageException();
1412}
1413
1414// Ping is similar to read except only enough of the image is read to
1415// determine the image columns, rows, and filesize. Access the
1416// columns(), rows(), and fileSize() attributes after invoking ping.
1417// The image data is not valid after calling ping.
1418void Magick::Image::ping ( const std::string &imageSpec_ )
1419{
1420 options()->fileName( imageSpec_ );
1421 ExceptionInfo exceptionInfo;
1422 GetExceptionInfo( &exceptionInfo );
1423 MagickCore::Image* image =
1424 PingImage( imageInfo(), &exceptionInfo );
1425 replaceImage( image );
1426 throwException( exceptionInfo );
1427 (void) DestroyExceptionInfo( &exceptionInfo );
1428}
1429
1430// Ping is similar to read except only enough of the image is read
1431// to determine the image columns, rows, and filesize. Access the
1432// columns(), rows(), and fileSize() attributes after invoking
1433// ping. The image data is not valid after calling ping.
1434void Magick::Image::ping ( const Blob& blob_ )
1435{
1436 ExceptionInfo exceptionInfo;
1437 GetExceptionInfo( &exceptionInfo );
1438 MagickCore::Image* image =
1439 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1440 replaceImage( image );
1441 throwException( exceptionInfo );
1442 (void) DestroyExceptionInfo( &exceptionInfo );
1443}
1444
1445// Execute a named process module using an argc/argv syntax similar to
1446// that accepted by a C 'main' routine. An exception is thrown if the
1447// requested process module doesn't exist, fails to load, or fails during
1448// execution.
cristyd99b0962010-05-29 23:14:26 +00001449void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
cristy3ed852e2009-09-05 21:47:34 +00001450{
1451 modifyImage();
1452
cristyeaedf062010-05-29 22:36:02 +00001453 size_t status =
cristy3ed852e2009-09-05 21:47:34 +00001454 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1455 &image()->exception );
1456
1457 if (status == false)
1458 throwException( image()->exception );
1459}
1460
1461// Quantize colors in image using current quantization settings
1462// Set measureError_ to true in order to measure quantization error
1463void Magick::Image::quantize ( const bool measureError_ )
1464{
1465 modifyImage();
1466
1467 if (measureError_)
1468 options()->quantizeInfo()->measure_error=MagickTrue;
1469 else
1470 options()->quantizeInfo()->measure_error=MagickFalse;
1471
1472 QuantizeImage( options()->quantizeInfo(), image() );
1473
1474 throwImageException();
1475}
1476
1477// Apply an arithmetic or bitwise operator to the image pixel quantums.
1478void Magick::Image::quantumOperator ( const ChannelType channel_,
1479 const MagickEvaluateOperator operator_,
1480 double rvalue_)
1481{
1482 ExceptionInfo exceptionInfo;
1483 GetExceptionInfo( &exceptionInfo );
1484 EvaluateImageChannel( image(), channel_, operator_, rvalue_, &exceptionInfo);
1485 throwException( exceptionInfo );
1486 (void) DestroyExceptionInfo( &exceptionInfo );
1487}
1488
cristyd99b0962010-05-29 23:14:26 +00001489void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00001490 const size_t columns_,
1491 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00001492 const ChannelType channel_,
1493 const MagickEvaluateOperator operator_,
1494 const double rvalue_)
1495{
1496 ExceptionInfo exceptionInfo;
1497 GetExceptionInfo( &exceptionInfo );
1498 RectangleInfo geometry;
1499 geometry.width = columns_;
1500 geometry.height = rows_;
1501 geometry.x = x_;
1502 geometry.y = y_;
1503 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1504 &exceptionInfo );
1505 EvaluateImageChannel( crop_image, channel_, operator_, rvalue_,
1506 &exceptionInfo );
1507 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1508 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1509 crop_image = DestroyImageList(crop_image);
1510 throwException( exceptionInfo );
1511 (void) DestroyExceptionInfo( &exceptionInfo );
1512}
1513
1514// Raise image (lighten or darken the edges of an image to give a 3-D
1515// raised or lowered effect)
1516void Magick::Image::raise ( const Geometry &geometry_ ,
1517 const bool raisedFlag_ )
1518{
1519 RectangleInfo raiseInfo = geometry_;
1520 modifyImage();
1521 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse );
1522 throwImageException();
1523}
1524
1525
1526// Random threshold image.
1527//
1528// Changes the value of individual pixels based on the intensity
1529// of each pixel compared to a random threshold. The result is a
1530// low-contrast, two color image. The thresholds_ argument is a
1531// geometry containing LOWxHIGH thresholds. If the string
1532// contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1533// 3, or 4 will be performed instead. If a channel_ argument is
1534// specified then only the specified channel is altered. This is
1535// a very fast alternative to 'quantize' based dithering.
1536void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1537{
1538 randomThresholdChannel(thresholds_,DefaultChannels);
1539}
1540void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1541 const ChannelType channel_ )
1542{
1543 ExceptionInfo exceptionInfo;
1544 GetExceptionInfo( &exceptionInfo );
1545 modifyImage();
1546 (void) RandomThresholdImageChannel( image(),
1547 channel_,
1548 static_cast<std::string>(thresholds_).c_str(),
1549 &exceptionInfo );
1550 throwImageException();
1551 (void) DestroyExceptionInfo( &exceptionInfo );
1552}
1553
1554// Read image into current object
1555void Magick::Image::read ( const std::string &imageSpec_ )
1556{
1557 options()->fileName( imageSpec_ );
1558
1559 ExceptionInfo exceptionInfo;
1560 GetExceptionInfo( &exceptionInfo );
1561 MagickCore::Image* image =
1562 ReadImage( imageInfo(), &exceptionInfo );
1563
1564 // Ensure that multiple image frames were not read.
1565 if ( image && image->next )
1566 {
1567 // Destroy any extra image frames
1568 MagickCore::Image* next = image->next;
1569 image->next = 0;
1570 next->previous = 0;
1571 DestroyImageList( next );
1572
1573 }
1574 replaceImage( image );
1575 throwException( exceptionInfo );
1576 if ( image )
1577 throwException( image->exception );
1578 (void) DestroyExceptionInfo( &exceptionInfo );
1579}
1580
1581// Read image of specified size into current object
1582void Magick::Image::read ( const Geometry &size_,
1583 const std::string &imageSpec_ )
1584{
1585 size( size_ );
1586 read( imageSpec_ );
1587}
1588
1589// Read image from in-memory BLOB
1590void Magick::Image::read ( const Blob &blob_ )
1591{
1592 ExceptionInfo exceptionInfo;
1593 GetExceptionInfo( &exceptionInfo );
1594 MagickCore::Image* image =
1595 BlobToImage( imageInfo(),
1596 static_cast<const void *>(blob_.data()),
1597 blob_.length(), &exceptionInfo );
1598 replaceImage( image );
1599 throwException( exceptionInfo );
1600 if ( image )
1601 throwException( image->exception );
1602 (void) DestroyExceptionInfo( &exceptionInfo );
1603}
1604
1605// Read image of specified size from in-memory BLOB
1606void Magick::Image::read ( const Blob &blob_,
1607 const Geometry &size_ )
1608{
1609 // Set image size
1610 size( size_ );
1611 // Read from Blob
1612 read( blob_ );
1613}
1614
1615// Read image of specified size and depth from in-memory BLOB
1616void Magick::Image::read ( const Blob &blob_,
1617 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001618 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00001619{
1620 // Set image size
1621 size( size_ );
1622 // Set image depth
1623 depth( depth_ );
1624 // Read from Blob
1625 read( blob_ );
1626}
1627
1628// Read image of specified size, depth, and format from in-memory BLOB
1629void Magick::Image::read ( const Blob &blob_,
1630 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001631 const size_t depth_,
cristy3ed852e2009-09-05 21:47:34 +00001632 const std::string &magick_ )
1633{
1634 // Set image size
1635 size( size_ );
1636 // Set image depth
1637 depth( depth_ );
1638 // Set image magick
1639 magick( magick_ );
1640 // Set explicit image format
1641 fileName( magick_ + ':');
1642 // Read from Blob
1643 read( blob_ );
1644}
1645
1646// Read image of specified size, and format from in-memory BLOB
1647void Magick::Image::read ( const Blob &blob_,
1648 const Geometry &size_,
1649 const std::string &magick_ )
1650{
1651 // Set image size
1652 size( size_ );
1653 // Set image magick
1654 magick( magick_ );
1655 // Set explicit image format
1656 fileName( magick_ + ':');
1657 // Read from Blob
1658 read( blob_ );
1659}
1660
1661// Read image based on raw pixels in memory (ConstituteImage)
cristyeaedf062010-05-29 22:36:02 +00001662void Magick::Image::read ( const size_t width_,
1663 const size_t height_,
cristy3ed852e2009-09-05 21:47:34 +00001664 const std::string &map_,
1665 const StorageType type_,
1666 const void *pixels_ )
1667{
1668 ExceptionInfo exceptionInfo;
1669 GetExceptionInfo( &exceptionInfo );
1670 MagickCore::Image* image =
1671 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1672 &exceptionInfo );
1673 replaceImage( image );
1674 throwException( exceptionInfo );
1675 if ( image )
1676 throwException( image->exception );
1677 (void) DestroyExceptionInfo( &exceptionInfo );
1678}
1679
cristy3ed852e2009-09-05 21:47:34 +00001680// Reduce noise in image
1681void Magick::Image::reduceNoise ( const double order_ )
1682{
1683 ExceptionInfo exceptionInfo;
1684 GetExceptionInfo( &exceptionInfo );
1685 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001686 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1687 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001688 replaceImage( newImage );
1689 throwException( exceptionInfo );
1690 (void) DestroyExceptionInfo( &exceptionInfo );
1691}
1692
1693// Resize image
1694void Magick::Image::resize( const Geometry &geometry_ )
1695{
1696 // Calculate new size. This code should be supported using binary arguments
1697 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00001698 ssize_t x = 0;
1699 ssize_t y = 0;
1700 size_t width = columns();
1701 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001702
1703 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1704 &x, &y,
1705 &width, &height );
1706
1707 ExceptionInfo exceptionInfo;
1708 GetExceptionInfo( &exceptionInfo );
1709 MagickCore::Image* newImage =
1710 ResizeImage( image(),
1711 width,
1712 height,
1713 image()->filter,
1714 1.0,
1715 &exceptionInfo);
1716 replaceImage( newImage );
1717 throwException( exceptionInfo );
1718 (void) DestroyExceptionInfo( &exceptionInfo );
1719}
1720
1721// Roll image
1722void Magick::Image::roll ( const Geometry &roll_ )
1723{
cristybb503372010-05-27 20:51:26 +00001724 ssize_t xOff = roll_.xOff();
cristy3ed852e2009-09-05 21:47:34 +00001725 if ( roll_.xNegative() )
1726 xOff = 0 - xOff;
cristybb503372010-05-27 20:51:26 +00001727 ssize_t yOff = roll_.yOff();
cristy3ed852e2009-09-05 21:47:34 +00001728 if ( roll_.yNegative() )
1729 yOff = 0 - yOff;
1730
1731 ExceptionInfo exceptionInfo;
1732 GetExceptionInfo( &exceptionInfo );
1733 MagickCore::Image* newImage =
1734 RollImage( image(), xOff, yOff, &exceptionInfo );
1735 replaceImage( newImage );
1736 throwException( exceptionInfo );
1737 (void) DestroyExceptionInfo( &exceptionInfo );
1738}
cristyeaedf062010-05-29 22:36:02 +00001739void Magick::Image::roll ( const size_t columns_,
1740 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00001741{
1742 ExceptionInfo exceptionInfo;
1743 GetExceptionInfo( &exceptionInfo );
1744 MagickCore::Image* newImage =
1745 RollImage( image(),
cristybb503372010-05-27 20:51:26 +00001746 static_cast<ssize_t>(columns_),
1747 static_cast<ssize_t>(rows_), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001748 replaceImage( newImage );
1749 throwException( exceptionInfo );
1750 (void) DestroyExceptionInfo( &exceptionInfo );
1751}
1752
1753// Rotate image
1754void Magick::Image::rotate ( const double degrees_ )
1755{
1756 ExceptionInfo exceptionInfo;
1757 GetExceptionInfo( &exceptionInfo );
1758 MagickCore::Image* newImage =
1759 RotateImage( image(), degrees_, &exceptionInfo);
1760 replaceImage( newImage );
1761 throwException( exceptionInfo );
1762 (void) DestroyExceptionInfo( &exceptionInfo );
1763}
1764
1765// Sample image
1766void Magick::Image::sample ( const Geometry &geometry_ )
1767{
cristybb503372010-05-27 20:51:26 +00001768 ssize_t x = 0;
1769 ssize_t y = 0;
1770 size_t width = columns();
1771 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001772
1773 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1774 &x, &y,
1775 &width, &height );
1776
1777 ExceptionInfo exceptionInfo;
1778 GetExceptionInfo( &exceptionInfo );
1779 MagickCore::Image* newImage =
1780 SampleImage( image(), width, height, &exceptionInfo );
1781 replaceImage( newImage );
1782 throwException( exceptionInfo );
1783 (void) DestroyExceptionInfo( &exceptionInfo );
1784}
1785
1786// Scale image
1787void Magick::Image::scale ( const Geometry &geometry_ )
1788{
cristybb503372010-05-27 20:51:26 +00001789 ssize_t x = 0;
1790 ssize_t y = 0;
1791 size_t width = columns();
1792 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001793
1794 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1795 &x, &y,
1796 &width, &height );
1797
1798 ExceptionInfo exceptionInfo;
1799 GetExceptionInfo( &exceptionInfo );
1800 MagickCore::Image* newImage =
1801 ScaleImage( image(), width, height, &exceptionInfo );
1802 replaceImage( newImage );
1803 throwException( exceptionInfo );
1804 (void) DestroyExceptionInfo( &exceptionInfo );
1805}
1806
1807// Segment (coalesce similar image components) by analyzing the
1808// histograms of the color components and identifying units that are
1809// homogeneous with the fuzzy c-means technique.
1810void Magick::Image::segment ( const double clusterThreshold_,
1811 const double smoothingThreshold_ )
1812{
1813 modifyImage();
1814 SegmentImage ( image(),
1815 options()->quantizeColorSpace(),
1816 (MagickBooleanType) options()->verbose(),
1817 clusterThreshold_,
1818 smoothingThreshold_ );
1819 throwImageException();
1820 SyncImage( image() );
1821 throwImageException();
1822}
1823
1824// Shade image using distant light source
1825void Magick::Image::shade ( const double azimuth_,
1826 const double elevation_,
1827 const bool colorShading_ )
1828{
1829 ExceptionInfo exceptionInfo;
1830 GetExceptionInfo( &exceptionInfo );
1831 MagickCore::Image* newImage =
1832 ShadeImage( image(),
1833 colorShading_ == true ? MagickTrue : MagickFalse,
1834 azimuth_,
1835 elevation_,
1836 &exceptionInfo);
1837 replaceImage( newImage );
1838 throwException( exceptionInfo );
1839 (void) DestroyExceptionInfo( &exceptionInfo );
1840}
1841
1842// Sharpen pixels in image
1843void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1844{
1845 ExceptionInfo exceptionInfo;
1846 GetExceptionInfo( &exceptionInfo );
1847 MagickCore::Image* newImage =
1848 SharpenImage( image(),
1849 radius_,
1850 sigma_,
1851 &exceptionInfo );
1852 replaceImage( newImage );
1853 throwException( exceptionInfo );
1854 (void) DestroyExceptionInfo( &exceptionInfo );
1855}
1856
1857void Magick::Image::sharpenChannel ( const ChannelType channel_,
1858 const double radius_, const double sigma_ )
1859{
1860 ExceptionInfo exceptionInfo;
1861 GetExceptionInfo( &exceptionInfo );
1862 MagickCore::Image* newImage =
1863 SharpenImageChannel( image(),
1864 channel_,
1865 radius_,
1866 sigma_,
1867 &exceptionInfo );
1868 replaceImage( newImage );
1869 throwException( exceptionInfo );
1870 (void) DestroyExceptionInfo( &exceptionInfo );
1871}
1872
1873// Shave pixels from image edges.
1874void Magick::Image::shave ( const Geometry &geometry_ )
1875{
1876 RectangleInfo shaveInfo = geometry_;
1877 ExceptionInfo exceptionInfo;
1878 GetExceptionInfo( &exceptionInfo );
1879 MagickCore::Image* newImage =
1880 ShaveImage( image(),
1881 &shaveInfo,
1882 &exceptionInfo);
1883 replaceImage( newImage );
1884 throwException( exceptionInfo );
1885 (void) DestroyExceptionInfo( &exceptionInfo );
1886}
1887
1888// Shear image
1889void Magick::Image::shear ( const double xShearAngle_,
1890 const double yShearAngle_ )
1891{
1892 ExceptionInfo exceptionInfo;
1893 GetExceptionInfo( &exceptionInfo );
1894 MagickCore::Image* newImage =
1895 ShearImage( image(),
1896 xShearAngle_,
1897 yShearAngle_,
1898 &exceptionInfo );
1899 replaceImage( newImage );
1900 throwException( exceptionInfo );
1901 (void) DestroyExceptionInfo( &exceptionInfo );
1902}
1903
1904// Contrast image
cristyeaedf062010-05-29 22:36:02 +00001905void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
cristy3ed852e2009-09-05 21:47:34 +00001906{
1907 modifyImage();
cristy9ee60942011-07-06 14:54:38 +00001908 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint );
cristy3ed852e2009-09-05 21:47:34 +00001909 throwImageException();
1910}
1911
1912// Solarize image (similar to effect seen when exposing a photographic
1913// film to light during the development process)
1914void Magick::Image::solarize ( const double factor_ )
1915{
1916 modifyImage();
1917 SolarizeImage ( image(), factor_ );
1918 throwImageException();
1919}
1920
1921// Sparse color image, given a set of coordinates, interpolates the colors
1922// found at those coordinates, across the whole image, using various methods.
1923//
1924void Magick::Image::sparseColor ( const ChannelType channel,
1925 const SparseColorMethod method,
cristybb503372010-05-27 20:51:26 +00001926 const size_t number_arguments,
cristy3ed852e2009-09-05 21:47:34 +00001927 const double *arguments )
1928{
1929 ExceptionInfo exceptionInfo;
1930 GetExceptionInfo( &exceptionInfo );
1931 MagickCore::Image* newImage = SparseColorImage ( image(), channel, method,
1932 number_arguments, arguments, &exceptionInfo );
1933 replaceImage( newImage );
1934 throwException( exceptionInfo );
1935 (void) DestroyExceptionInfo( &exceptionInfo );
1936}
1937
1938// Spread pixels randomly within image by specified ammount
cristyeaedf062010-05-29 22:36:02 +00001939void Magick::Image::spread ( const size_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +00001940{
1941 ExceptionInfo exceptionInfo;
1942 GetExceptionInfo( &exceptionInfo );
1943 MagickCore::Image* newImage =
1944 SpreadImage( image(),
1945 amount_,
1946 &exceptionInfo );
1947 replaceImage( newImage );
1948 throwException( exceptionInfo );
1949 (void) DestroyExceptionInfo( &exceptionInfo );
1950}
1951
1952// Add a digital watermark to the image (based on second image)
1953void Magick::Image::stegano ( const Image &watermark_ )
1954{
1955 ExceptionInfo exceptionInfo;
1956 GetExceptionInfo( &exceptionInfo );
1957 MagickCore::Image* newImage =
1958 SteganoImage( image(),
1959 watermark_.constImage(),
1960 &exceptionInfo);
1961 replaceImage( newImage );
1962 throwException( exceptionInfo );
1963 (void) DestroyExceptionInfo( &exceptionInfo );
1964}
1965
1966// Stereo image (left image is current image)
1967void Magick::Image::stereo ( const Image &rightImage_ )
1968{
1969 ExceptionInfo exceptionInfo;
1970 GetExceptionInfo( &exceptionInfo );
1971 MagickCore::Image* newImage =
1972 StereoImage( image(),
1973 rightImage_.constImage(),
1974 &exceptionInfo);
1975 replaceImage( newImage );
1976 throwException( exceptionInfo );
1977 (void) DestroyExceptionInfo( &exceptionInfo );
1978}
1979
1980// Swirl image
1981void Magick::Image::swirl ( const double degrees_ )
1982{
1983 ExceptionInfo exceptionInfo;
1984 GetExceptionInfo( &exceptionInfo );
1985 MagickCore::Image* newImage =
1986 SwirlImage( image(), degrees_,
1987 &exceptionInfo);
1988 replaceImage( newImage );
1989 throwException( exceptionInfo );
1990 (void) DestroyExceptionInfo( &exceptionInfo );
1991}
1992
1993// Texture image
1994void Magick::Image::texture ( const Image &texture_ )
1995{
1996 modifyImage();
1997 TextureImage( image(), texture_.constImage() );
1998 throwImageException();
1999}
2000
2001// Threshold image
2002void Magick::Image::threshold ( const double threshold_ )
2003{
2004 modifyImage();
2005 BilevelImage( image(), threshold_ );
2006 throwImageException();
2007}
2008
2009// Transform image based on image geometry only
2010void Magick::Image::transform ( const Geometry &imageGeometry_ )
2011{
2012 modifyImage();
2013 TransformImage ( &(image()), 0,
2014 std::string(imageGeometry_).c_str() );
2015 throwImageException();
2016}
2017// Transform image based on image and crop geometries
2018void Magick::Image::transform ( const Geometry &imageGeometry_,
2019 const Geometry &cropGeometry_ )
2020{
2021 modifyImage();
2022 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2023 std::string(imageGeometry_).c_str() );
2024 throwImageException();
2025}
2026
2027// Add matte image to image, setting pixels matching color to transparent
2028void Magick::Image::transparent ( const Color &color_ )
2029{
2030 if ( !color_.isValid() )
2031 {
2032 throwExceptionExplicit( OptionError,
2033 "Color argument is invalid" );
2034 }
2035
2036 std::string color = color_;
2037
cristy4c08aed2011-07-01 19:47:50 +00002038 PixelInfo target;
cristy3ed852e2009-09-05 21:47:34 +00002039 (void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
2040 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00002041 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse );
cristy3ed852e2009-09-05 21:47:34 +00002042 throwImageException();
2043}
2044
2045// Add matte image to image, setting pixels matching color to transparent
2046void Magick::Image::transparentChroma(const Color &colorLow_,
2047 const Color &colorHigh_)
2048{
2049 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2050 {
2051 throwExceptionExplicit( OptionError,
2052 "Color argument is invalid" );
2053 }
2054
2055 std::string colorLow = colorLow_;
2056 std::string colorHigh = colorHigh_;
2057
cristy4c08aed2011-07-01 19:47:50 +00002058 PixelInfo targetLow;
2059 PixelInfo targetHigh;
cristy3ed852e2009-09-05 21:47:34 +00002060 (void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
2061 &image()->exception);
2062 (void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
2063 &image()->exception);
2064 modifyImage();
2065 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
cristy4c08aed2011-07-01 19:47:50 +00002066 TransparentAlpha, MagickFalse );
cristy3ed852e2009-09-05 21:47:34 +00002067 throwImageException();
2068}
2069
2070
2071// Trim edges that are the background color from the image
2072void Magick::Image::trim ( void )
2073{
2074 ExceptionInfo exceptionInfo;
2075 GetExceptionInfo( &exceptionInfo );
2076 MagickCore::Image* newImage =
2077 TrimImage( image(), &exceptionInfo);
2078 replaceImage( newImage );
2079 throwException( exceptionInfo );
2080 (void) DestroyExceptionInfo( &exceptionInfo );
2081}
2082
2083// Replace image with a sharpened version of the original image
2084// using the unsharp mask algorithm.
2085// radius_
2086// the radius of the Gaussian, in pixels, not counting the
2087// center pixel.
2088// sigma_
2089// the standard deviation of the Gaussian, in pixels.
2090// amount_
2091// the percentage of the difference between the original and
2092// the blur image that is added back into the original.
2093// threshold_
2094// the threshold in pixels needed to apply the diffence amount.
2095void Magick::Image::unsharpmask ( const double radius_,
2096 const double sigma_,
2097 const double amount_,
2098 const double threshold_ )
2099{
2100 ExceptionInfo exceptionInfo;
2101 GetExceptionInfo( &exceptionInfo );
2102 MagickCore::Image* newImage =
2103 UnsharpMaskImage( image(),
2104 radius_,
2105 sigma_,
2106 amount_,
2107 threshold_,
2108 &exceptionInfo );
2109 replaceImage( newImage );
2110 throwException( exceptionInfo );
2111 (void) DestroyExceptionInfo( &exceptionInfo );
2112}
2113
2114void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2115 const double radius_,
2116 const double sigma_,
2117 const double amount_,
2118 const double threshold_ )
2119{
2120 ExceptionInfo exceptionInfo;
2121 GetExceptionInfo( &exceptionInfo );
2122 MagickCore::Image* newImage =
2123 UnsharpMaskImageChannel( image(),
2124 channel_,
2125 radius_,
2126 sigma_,
2127 amount_,
2128 threshold_,
2129 &exceptionInfo );
2130 replaceImage( newImage );
2131 throwException( exceptionInfo );
2132 (void) DestroyExceptionInfo( &exceptionInfo );
2133}
2134
2135// Map image pixels to a sine wave
2136void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2137{
2138 ExceptionInfo exceptionInfo;
2139 GetExceptionInfo( &exceptionInfo );
2140 MagickCore::Image* newImage =
2141 WaveImage( image(),
2142 amplitude_,
2143 wavelength_,
2144 &exceptionInfo);
2145 replaceImage( newImage );
2146 throwException( exceptionInfo );
2147 (void) DestroyExceptionInfo( &exceptionInfo );
2148}
2149
2150// Write image to file
2151void Magick::Image::write( const std::string &imageSpec_ )
2152{
2153 modifyImage();
2154 fileName( imageSpec_ );
2155 WriteImage( imageInfo(), image() );
2156 throwImageException();
2157}
2158
2159// Write image to in-memory BLOB
2160void Magick::Image::write ( Blob *blob_ )
2161{
2162 modifyImage();
2163 size_t length = 2048; // Efficient size for small images
2164 ExceptionInfo exceptionInfo;
2165 GetExceptionInfo( &exceptionInfo );
2166 void* data = ImageToBlob( imageInfo(),
2167 image(),
2168 &length,
2169 &exceptionInfo);
2170 throwException( exceptionInfo );
2171 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2172 throwImageException();
2173 (void) DestroyExceptionInfo( &exceptionInfo );
2174}
2175void Magick::Image::write ( Blob *blob_,
2176 const std::string &magick_ )
2177{
2178 modifyImage();
2179 magick(magick_);
2180 size_t length = 2048; // Efficient size for small images
2181 ExceptionInfo exceptionInfo;
2182 GetExceptionInfo( &exceptionInfo );
2183 void* data = ImageToBlob( imageInfo(),
2184 image(),
2185 &length,
2186 &exceptionInfo);
2187 throwException( exceptionInfo );
2188 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2189 throwImageException();
2190 (void) DestroyExceptionInfo( &exceptionInfo );
2191}
2192void Magick::Image::write ( Blob *blob_,
2193 const std::string &magick_,
cristyeaedf062010-05-29 22:36:02 +00002194 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002195{
2196 modifyImage();
2197 magick(magick_);
2198 depth(depth_);
2199 size_t length = 2048; // Efficient size for small images
2200 ExceptionInfo exceptionInfo;
2201 GetExceptionInfo( &exceptionInfo );
2202 void* data = ImageToBlob( imageInfo(),
2203 image(),
2204 &length,
2205 &exceptionInfo);
2206 throwException( exceptionInfo );
2207 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2208 throwImageException();
2209 (void) DestroyExceptionInfo( &exceptionInfo );
2210}
2211
2212// Write image to an array of pixels with storage type specified
2213// by user (ExportImagePixels), e.g.
2214// image.write( 0, 0, 640, 1, "RGB", 0, pixels );
cristyd99b0962010-05-29 23:14:26 +00002215void Magick::Image::write ( const ssize_t x_,
2216 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00002217 const size_t columns_,
2218 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00002219 const std::string &map_,
2220 const StorageType type_,
2221 void *pixels_ )
2222{
2223 ExceptionInfo exceptionInfo;
2224 GetExceptionInfo( &exceptionInfo );
2225 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2226 pixels_,
2227 &exceptionInfo);
2228 throwException( exceptionInfo );
2229 (void) DestroyExceptionInfo( &exceptionInfo );
2230}
2231
2232// Zoom image
2233void Magick::Image::zoom( const Geometry &geometry_ )
2234{
2235 // Calculate new size. This code should be supported using binary arguments
2236 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00002237 ssize_t x = 0;
2238 ssize_t y = 0;
2239 size_t width = columns();
2240 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00002241
2242 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2243 &x, &y,
2244 &width, &height );
2245
2246 ExceptionInfo exceptionInfo;
2247 GetExceptionInfo( &exceptionInfo );
2248 MagickCore::Image* newImage =
cristy391f1ce2010-09-09 17:23:28 +00002249 ResizeImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00002250 width,
2251 height,
cristy391f1ce2010-09-09 17:23:28 +00002252 image()->filter,
2253 image()->blur,
cristy3ed852e2009-09-05 21:47:34 +00002254 &exceptionInfo);
2255 replaceImage( newImage );
2256 throwException( exceptionInfo );
2257 (void) DestroyExceptionInfo( &exceptionInfo );
2258}
2259
2260/*
2261 * Methods for setting image attributes
2262 *
2263 */
2264
2265// Join images into a single multi-image file
2266void Magick::Image::adjoin ( const bool flag_ )
2267{
2268 modifyImage();
2269 options()->adjoin( flag_ );
2270}
2271bool Magick::Image::adjoin ( void ) const
2272{
2273 return constOptions()->adjoin();
2274}
2275
2276// Remove pixel aliasing
2277void Magick::Image::antiAlias( const bool flag_ )
2278{
2279 modifyImage();
cristyeaedf062010-05-29 22:36:02 +00002280 options()->antiAlias( static_cast<size_t>(flag_) );
cristy3ed852e2009-09-05 21:47:34 +00002281}
2282bool Magick::Image::antiAlias( void )
2283{
2284 return static_cast<bool>( options()->antiAlias( ) );
2285}
2286
2287// Animation inter-frame delay
cristyeaedf062010-05-29 22:36:02 +00002288void Magick::Image::animationDelay ( const size_t delay_ )
cristy3ed852e2009-09-05 21:47:34 +00002289{
2290 modifyImage();
2291 image()->delay = delay_;
2292}
cristyeaedf062010-05-29 22:36:02 +00002293size_t Magick::Image::animationDelay ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002294{
2295 return constImage()->delay;
2296}
2297
2298// Number of iterations to play animation
cristyeaedf062010-05-29 22:36:02 +00002299void Magick::Image::animationIterations ( const size_t iterations_ )
cristy3ed852e2009-09-05 21:47:34 +00002300{
2301 modifyImage();
2302 image()->iterations = iterations_;
2303}
cristyeaedf062010-05-29 22:36:02 +00002304size_t Magick::Image::animationIterations ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002305{
2306 return constImage()->iterations;
2307}
2308
2309// Access/Update a named image attribute
2310void Magick::Image::attribute ( const std::string name_,
2311 const std::string value_ )
2312{
2313 modifyImage();
2314 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2315}
2316std::string Magick::Image::attribute ( const std::string name_ )
2317{
2318 const char *value = GetImageProperty( constImage(), name_.c_str() );
2319
2320 if ( value )
2321 return std::string( value );
2322
2323 return std::string(); // Intentionally no exception
2324}
2325
2326// Background color
cristy391f1ce2010-09-09 17:23:28 +00002327void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002328{
2329 modifyImage();
2330
cristy391f1ce2010-09-09 17:23:28 +00002331 if ( backgroundColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002332 {
cristy391f1ce2010-09-09 17:23:28 +00002333 image()->background_color = backgroundColor_;
cristy3ed852e2009-09-05 21:47:34 +00002334 }
2335 else
2336 {
cristy391f1ce2010-09-09 17:23:28 +00002337 image()->background_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002338 }
2339
cristy391f1ce2010-09-09 17:23:28 +00002340 options()->backgroundColor( backgroundColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002341}
2342Magick::Color Magick::Image::backgroundColor ( void ) const
2343{
2344 return constOptions()->backgroundColor( );
2345}
2346
2347// Background fill texture
2348void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2349{
2350 modifyImage();
2351 options()->backgroundTexture( backgroundTexture_ );
2352}
2353std::string Magick::Image::backgroundTexture ( void ) const
2354{
2355 return constOptions()->backgroundTexture( );
2356}
2357
2358// Original image columns
cristyeaedf062010-05-29 22:36:02 +00002359size_t Magick::Image::baseColumns ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002360{
2361 return constImage()->magick_columns;
2362}
2363
2364// Original image name
2365std::string Magick::Image::baseFilename ( void ) const
2366{
2367 return std::string(constImage()->magick_filename);
2368}
2369
2370// Original image rows
cristyeaedf062010-05-29 22:36:02 +00002371size_t Magick::Image::baseRows ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002372{
2373 return constImage()->magick_rows;
2374}
2375
2376// Border color
cristy391f1ce2010-09-09 17:23:28 +00002377void Magick::Image::borderColor ( const Color &borderColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002378{
2379 modifyImage();
2380
cristy391f1ce2010-09-09 17:23:28 +00002381 if ( borderColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002382 {
cristy391f1ce2010-09-09 17:23:28 +00002383 image()->border_color = borderColor_;
cristy3ed852e2009-09-05 21:47:34 +00002384 }
2385 else
2386 {
cristy391f1ce2010-09-09 17:23:28 +00002387 image()->border_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002388 }
2389
cristy391f1ce2010-09-09 17:23:28 +00002390 options()->borderColor( borderColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002391}
2392Magick::Color Magick::Image::borderColor ( void ) const
2393{
2394 return constOptions()->borderColor( );
2395}
2396
2397// Return smallest bounding box enclosing non-border pixels. The
2398// current fuzz value is used when discriminating between pixels.
2399// This is the crop bounding box used by crop(Geometry(0,0));
2400Magick::Geometry Magick::Image::boundingBox ( void ) const
2401{
2402 ExceptionInfo exceptionInfo;
2403 GetExceptionInfo( &exceptionInfo );
2404 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2405 throwException( exceptionInfo );
2406 (void) DestroyExceptionInfo( &exceptionInfo );
2407 return Geometry( bbox );
2408}
2409
2410// Text bounding-box base color
2411void Magick::Image::boxColor ( const Color &boxColor_ )
2412{
2413 modifyImage();
2414 options()->boxColor( boxColor_ );
2415}
2416Magick::Color Magick::Image::boxColor ( void ) const
2417{
2418 return constOptions()->boxColor( );
2419}
2420
2421// Pixel cache threshold. Once this threshold is exceeded, all
2422// subsequent pixels cache operations are to/from disk.
2423// This setting is shared by all Image objects.
2424/* static */
cristyeaedf062010-05-29 22:36:02 +00002425void Magick::Image::cacheThreshold ( const size_t threshold_ )
cristy3ed852e2009-09-05 21:47:34 +00002426{
2427 SetMagickResourceLimit( MemoryResource, threshold_ );
2428}
2429
2430void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2431{
2432 modifyImage();
2433 image()->chromaticity.blue_primary.x = x_;
2434 image()->chromaticity.blue_primary.y = y_;
2435}
2436void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2437{
2438 *x_ = constImage()->chromaticity.blue_primary.x;
2439 *y_ = constImage()->chromaticity.blue_primary.y;
2440}
2441
2442void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2443{
2444 modifyImage();
2445 image()->chromaticity.green_primary.x = x_;
2446 image()->chromaticity.green_primary.y = y_;
2447}
2448void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2449{
2450 *x_ = constImage()->chromaticity.green_primary.x;
2451 *y_ = constImage()->chromaticity.green_primary.y;
2452}
2453
2454void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2455{
2456 modifyImage();
2457 image()->chromaticity.red_primary.x = x_;
2458 image()->chromaticity.red_primary.y = y_;
2459}
2460void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2461{
2462 *x_ = constImage()->chromaticity.red_primary.x;
2463 *y_ = constImage()->chromaticity.red_primary.y;
2464}
2465
2466void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2467{
2468 modifyImage();
2469 image()->chromaticity.white_point.x = x_;
2470 image()->chromaticity.white_point.y = y_;
2471}
2472void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2473{
2474 *x_ = constImage()->chromaticity.white_point.x;
2475 *y_ = constImage()->chromaticity.white_point.y;
2476}
2477
2478// Set image storage class
2479void Magick::Image::classType ( const ClassType class_ )
2480{
2481 if ( classType() == PseudoClass && class_ == DirectClass )
2482 {
2483 // Use SyncImage to synchronize the DirectClass pixels with the
2484 // color map and then set to DirectClass type.
2485 modifyImage();
2486 SyncImage( image() );
2487 image()->colormap = (PixelPacket *)
2488 RelinquishMagickMemory( image()->colormap );
2489 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2490 return;
2491 }
2492
2493 if ( classType() == DirectClass && class_ == PseudoClass )
2494 {
2495 // Quantize to create PseudoClass color map
2496 modifyImage();
cristye6bbc092010-05-12 17:00:47 +00002497 quantizeColors(MaxColormapSize);
cristy3ed852e2009-09-05 21:47:34 +00002498 quantize();
2499 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2500 }
2501}
2502
2503// Associate a clip mask with the image. The clip mask must be the
2504// same dimensions as the image. Pass an invalid image to unset an
2505// existing clip mask.
2506void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2507{
2508 modifyImage();
2509
2510 if( clipMask_.isValid() )
2511 {
2512 // Set clip mask
2513 SetImageClipMask( image(), clipMask_.constImage() );
2514 }
2515 else
2516 {
2517 // Unset existing clip mask
2518 SetImageClipMask( image(), 0 );
2519 }
2520}
2521Magick::Image Magick::Image::clipMask ( void ) const
2522{
2523 ExceptionInfo exceptionInfo;
2524 GetExceptionInfo( &exceptionInfo );
2525 MagickCore::Image* image =
2526 GetImageClipMask( constImage(), &exceptionInfo );
2527 throwException( exceptionInfo );
2528 (void) DestroyExceptionInfo( &exceptionInfo );
2529 return Magick::Image( image );
2530}
2531
2532void Magick::Image::colorFuzz ( const double fuzz_ )
2533{
2534 modifyImage();
2535 image()->fuzz = fuzz_;
2536 options()->colorFuzz( fuzz_ );
2537}
2538double Magick::Image::colorFuzz ( void ) const
2539{
2540 return constOptions()->colorFuzz( );
2541}
2542
2543// Set color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002544void Magick::Image::colorMap ( const size_t index_,
cristy3ed852e2009-09-05 21:47:34 +00002545 const Color &color_ )
2546{
2547 MagickCore::Image* imageptr = image();
2548
2549 if (index_ > (MaxColormapSize-1) )
2550 throwExceptionExplicit( OptionError,
2551 "Colormap index must be less than MaxColormapSize" );
2552
2553 if ( !color_.isValid() )
2554 throwExceptionExplicit( OptionError,
2555 "Color argument is invalid");
2556 modifyImage();
2557
2558 // Ensure that colormap size is large enough
2559 if ( colorMapSize() < (index_+1) )
2560 colorMapSize( index_ + 1 );
2561
2562 // Set color at index in colormap
2563 (imageptr->colormap)[index_] = color_;
2564}
2565// Return color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002566Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
cristy3ed852e2009-09-05 21:47:34 +00002567{
2568 const MagickCore::Image* imageptr = constImage();
2569
2570 if ( !imageptr->colormap )
2571 throwExceptionExplicit( OptionError,
2572 "Image does not contain a colormap");
2573
2574 if ( index_ > imageptr->colors-1 )
2575 throwExceptionExplicit( OptionError,
2576 "Index out of range");
2577
2578 return Magick::Color( (imageptr->colormap)[index_] );
2579}
2580
2581// Colormap size (number of colormap entries)
cristyeaedf062010-05-29 22:36:02 +00002582void Magick::Image::colorMapSize ( const size_t entries_ )
cristy3ed852e2009-09-05 21:47:34 +00002583{
2584 if (entries_ >MaxColormapSize )
2585 throwExceptionExplicit( OptionError,
2586 "Colormap entries must not exceed MaxColormapSize" );
2587
2588 modifyImage();
2589
2590 MagickCore::Image* imageptr = image();
2591
2592 if( !imageptr->colormap )
2593 {
2594 // Allocate colormap
2595 imageptr->colormap =
2596 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2597 imageptr->colors = 0;
2598 }
2599 else if ( entries_ > imageptr->colors )
2600 {
2601 // Re-allocate colormap
2602 imageptr->colormap=(PixelPacket *)
2603 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2604 }
2605
2606 // Initialize any new colormap entries as all black
2607 Color black(0,0,0);
cristyeaedf062010-05-29 22:36:02 +00002608 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
cristy3ed852e2009-09-05 21:47:34 +00002609 (imageptr->colormap)[i] = black;
2610
2611 imageptr->colors = entries_;
2612}
cristyeaedf062010-05-29 22:36:02 +00002613size_t Magick::Image::colorMapSize ( void )
cristy3ed852e2009-09-05 21:47:34 +00002614{
2615 const MagickCore::Image* imageptr = constImage();
2616
2617 if ( !imageptr->colormap )
2618 throwExceptionExplicit( OptionError,
2619 "Image does not contain a colormap");
2620
2621 return imageptr->colors;
2622}
2623
2624// Image colorspace
2625void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2626{
2627 // Nothing to do?
2628 if ( image()->colorspace == colorSpace_ )
2629 return;
2630
2631 modifyImage();
2632
2633 if ( colorSpace_ != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002634 colorSpace_ != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002635 colorSpace_ != TransparentColorspace &&
2636 colorSpace_ != GRAYColorspace )
2637 {
2638 if (image()->colorspace != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002639 image()->colorspace != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002640 image()->colorspace != TransparentColorspace &&
2641 image()->colorspace != GRAYColorspace)
2642 {
2643 /* Transform to RGB colorspace as intermediate step */
2644 TransformRGBImage( image(), image()->colorspace );
2645 throwImageException();
2646 }
2647 /* Transform to final non-RGB colorspace */
2648 RGBTransformImage( image(), colorSpace_ );
2649 throwImageException();
2650 return;
2651 }
2652
2653 if ( colorSpace_ == RGBColorspace ||
cristy510d06a2011-07-06 23:43:54 +00002654 colorSpace_ == sRGBColorspace ||
cristy3ed852e2009-09-05 21:47:34 +00002655 colorSpace_ == TransparentColorspace ||
2656 colorSpace_ == GRAYColorspace )
2657 {
2658 /* Transform to a RGB-type colorspace */
2659 TransformRGBImage( image(), image()->colorspace );
2660 throwImageException();
2661 return;
2662 }
2663}
2664Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2665{
2666 return constImage()->colorspace;
2667}
2668
2669// Set image colorspace type.
2670void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2671{
2672 modifyImage();
2673 options()->colorspaceType( colorSpace_ );
2674}
2675Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2676{
2677 return constOptions()->colorspaceType();
2678}
2679
2680
2681// Comment string
2682void Magick::Image::comment ( const std::string &comment_ )
2683{
2684 modifyImage();
2685 SetImageProperty( image(), "Comment", NULL );
2686 if ( comment_.length() > 0 )
2687 SetImageProperty( image(), "Comment", comment_.c_str() );
2688 throwImageException();
2689}
2690std::string Magick::Image::comment ( void ) const
2691{
2692 const char *value = GetImageProperty( constImage(), "Comment" );
2693
2694 if ( value )
2695 return std::string( value );
2696
2697 return std::string(); // Intentionally no exception
2698}
2699
2700// Composition operator to be used when composition is implicitly used
2701// (such as for image flattening).
2702void Magick::Image::compose (const CompositeOperator compose_)
2703{
2704 image()->compose=compose_;
2705}
2706
2707Magick::CompositeOperator Magick::Image::compose ( void ) const
2708{
2709 return constImage()->compose;
2710}
2711
2712// Compression algorithm
2713void Magick::Image::compressType ( const CompressionType compressType_ )
2714{
2715 modifyImage();
2716 image()->compression = compressType_;
2717 options()->compressType( compressType_ );
2718}
2719Magick::CompressionType Magick::Image::compressType ( void ) const
2720{
2721 return constImage()->compression;
2722}
2723
2724// Enable printing of debug messages from ImageMagick
2725void Magick::Image::debug ( const bool flag_ )
2726{
2727 modifyImage();
2728 options()->debug( flag_ );
2729}
2730bool Magick::Image::debug ( void ) const
2731{
2732 return constOptions()->debug();
2733}
2734
2735// Tagged image format define (set/access coder-specific option) The
2736// magick_ option specifies the coder the define applies to. The key_
2737// option provides the key specific to that coder. The value_ option
2738// provides the value to set (if any). See the defineSet() method if the
2739// key must be removed entirely.
2740void Magick::Image::defineValue ( const std::string &magick_,
2741 const std::string &key_,
2742 const std::string &value_ )
2743{
2744 modifyImage();
2745 std::string format = magick_ + ":" + key_;
2746 std::string option = value_;
2747 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2748}
2749std::string Magick::Image::defineValue ( const std::string &magick_,
2750 const std::string &key_ ) const
2751{
2752 std::string definition = magick_ + ":" + key_;
2753 const char *option =
2754 GetImageOption ( constImageInfo(), definition.c_str() );
2755 if (option)
2756 return std::string( option );
2757 return std::string( );
2758}
2759
2760// Tagged image format define. Similar to the defineValue() method
2761// except that passing the flag_ value 'true' creates a value-less
2762// define with that format and key. Passing the flag_ value 'false'
2763// removes any existing matching definition. The method returns 'true'
2764// if a matching key exists, and 'false' if no matching key exists.
2765void Magick::Image::defineSet ( const std::string &magick_,
2766 const std::string &key_,
2767 bool flag_ )
2768{
2769 modifyImage();
2770 std::string definition = magick_ + ":" + key_;
2771 if (flag_)
2772 {
2773 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2774 }
2775 else
2776 {
2777 DeleteImageOption( imageInfo(), definition.c_str() );
2778 }
2779}
2780bool Magick::Image::defineSet ( const std::string &magick_,
2781 const std::string &key_ ) const
2782{
2783 std::string key = magick_ + ":" + key_;
2784 const char *option =
2785 GetImageOption ( constImageInfo(), key.c_str() );
2786 if (option)
2787 return true;
2788 return false;
2789}
2790
2791// Pixel resolution
2792void Magick::Image::density ( const Geometry &density_ )
2793{
2794 modifyImage();
2795 options()->density( density_ );
2796 if ( density_.isValid() )
2797 {
2798 image()->x_resolution = density_.width();
2799 if ( density_.height() != 0 )
2800 {
2801 image()->y_resolution = density_.height();
2802 }
2803 else
2804 {
2805 image()->y_resolution = density_.width();
2806 }
2807 }
2808 else
2809 {
2810 // Reset to default
2811 image()->x_resolution = 0;
2812 image()->y_resolution = 0;
2813 }
2814}
2815Magick::Geometry Magick::Image::density ( void ) const
2816{
2817 if (isValid())
2818 {
cristy35ef8242010-06-03 16:24:13 +00002819 ssize_t x_resolution=72;
2820 ssize_t y_resolution=72;
cristy3ed852e2009-09-05 21:47:34 +00002821
2822 if (constImage()->x_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002823 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002824
2825 if (constImage()->y_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002826 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002827
2828 return Geometry(x_resolution,y_resolution);
2829 }
2830
2831 return constOptions()->density( );
2832}
2833
2834// Image depth (bits allocated to red/green/blue components)
cristyeaedf062010-05-29 22:36:02 +00002835void Magick::Image::depth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002836{
cristyeaedf062010-05-29 22:36:02 +00002837 size_t depth = depth_;
cristy3ed852e2009-09-05 21:47:34 +00002838
2839 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2840 depth=MAGICKCORE_QUANTUM_DEPTH;
2841
2842 modifyImage();
2843 image()->depth=depth;
2844 options()->depth( depth );
2845}
cristyeaedf062010-05-29 22:36:02 +00002846size_t Magick::Image::depth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002847{
2848 return constImage()->depth;
2849}
2850
2851std::string Magick::Image::directory ( void ) const
2852{
2853 if ( constImage()->directory )
2854 return std::string( constImage()->directory );
2855
2856 throwExceptionExplicit( CorruptImageWarning,
2857 "Image does not contain a directory");
2858
2859 return std::string();
2860}
2861
2862// Endianness (little like Intel or big like SPARC) for image
2863// formats which support endian-specific options.
2864void Magick::Image::endian ( const Magick::EndianType endian_ )
2865{
2866 modifyImage();
2867 options()->endian( endian_ );
2868 image()->endian = endian_;
2869}
2870Magick::EndianType Magick::Image::endian ( void ) const
2871{
2872 return constImage()->endian;
2873}
2874
2875// EXIF profile (BLOB)
2876void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
2877{
2878 modifyImage();
2879 if ( exifProfile_.data() != 0 )
2880 {
2881 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
2882 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
2883 (void) SetImageProfile( image(), "exif", exif_profile);
2884 exif_profile =DestroyStringInfo( exif_profile );
2885 }
2886}
2887Magick::Blob Magick::Image::exifProfile( void ) const
2888{
2889 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
2890 if ( exif_profile == (StringInfo *) NULL)
2891 return Blob( 0, 0 );
2892 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
2893}
2894
2895// Image file name
2896void Magick::Image::fileName ( const std::string &fileName_ )
2897{
2898 modifyImage();
2899
2900 fileName_.copy( image()->filename,
2901 sizeof(image()->filename) - 1 );
2902 image()->filename[ fileName_.length() ] = 0; // Null terminate
2903
2904 options()->fileName( fileName_ );
2905
2906}
2907std::string Magick::Image::fileName ( void ) const
2908{
2909 return constOptions()->fileName( );
2910}
2911
2912// Image file size
2913off_t Magick::Image::fileSize ( void ) const
2914{
2915 return (off_t) GetBlobSize( constImage() );
2916}
2917
2918// Color to use when drawing inside an object
2919void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
2920{
2921 modifyImage();
2922 options()->fillColor(fillColor_);
2923}
2924Magick::Color Magick::Image::fillColor ( void ) const
2925{
2926 return constOptions()->fillColor();
2927}
2928
2929// Rule to use when filling drawn objects
2930void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
2931{
2932 modifyImage();
2933 options()->fillRule(fillRule_);
2934}
2935Magick::FillRule Magick::Image::fillRule ( void ) const
2936{
2937 return constOptions()->fillRule();
2938}
2939
2940// Pattern to use while filling drawn objects.
2941void Magick::Image::fillPattern ( const Image &fillPattern_ )
2942{
2943 modifyImage();
2944 if(fillPattern_.isValid())
2945 options()->fillPattern( fillPattern_.constImage() );
2946 else
2947 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
2948}
2949Magick::Image Magick::Image::fillPattern ( void ) const
2950{
2951 // FIXME: This is inordinately innefficient
2952 Image texture;
2953
2954 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
2955
2956 if ( tmpTexture )
2957 {
2958 ExceptionInfo exceptionInfo;
2959 GetExceptionInfo( &exceptionInfo );
2960 MagickCore::Image* image =
2961 CloneImage( tmpTexture,
2962 0, // columns
2963 0, // rows
2964 MagickTrue, // orphan
2965 &exceptionInfo);
2966 texture.replaceImage( image );
2967 throwException( exceptionInfo );
2968 (void) DestroyExceptionInfo( &exceptionInfo );
2969 }
2970 return texture;
2971}
2972
2973// Filter used by zoom
2974void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
2975{
2976 modifyImage();
2977 image()->filter = filterType_;
2978}
2979Magick::FilterTypes Magick::Image::filterType ( void ) const
2980{
2981 return constImage()->filter;
2982}
2983
2984// Font name
2985void Magick::Image::font ( const std::string &font_ )
2986{
2987 modifyImage();
2988 options()->font( font_ );
2989}
2990std::string Magick::Image::font ( void ) const
2991{
2992 return constOptions()->font( );
2993}
2994
2995// Font point size
2996void Magick::Image::fontPointsize ( const double pointSize_ )
2997{
2998 modifyImage();
2999 options()->fontPointsize( pointSize_ );
3000}
3001double Magick::Image::fontPointsize ( void ) const
3002{
3003 return constOptions()->fontPointsize( );
3004}
3005
3006// Font type metrics
3007void Magick::Image::fontTypeMetrics( const std::string &text_,
3008 TypeMetric *metrics )
3009{
3010 DrawInfo *drawInfo = options()->drawInfo();
3011 drawInfo->text = const_cast<char *>(text_.c_str());
3012 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
3013 drawInfo->text = 0;
3014}
3015
3016// Image format string
3017std::string Magick::Image::format ( void ) const
3018{
3019 ExceptionInfo exceptionInfo;
3020 GetExceptionInfo( &exceptionInfo );
3021 const MagickInfo * magick_info
3022 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3023 throwException( exceptionInfo );
3024 (void) DestroyExceptionInfo( &exceptionInfo );
3025
3026 if (( magick_info != 0 ) &&
3027 ( *magick_info->description != '\0' ))
3028 return std::string(magick_info->description);
3029
3030 throwExceptionExplicit( CorruptImageWarning,
3031 "Unrecognized image magick type" );
3032 return std::string();
3033}
3034
3035// Gamma adjustment
3036double Magick::Image::gamma ( void ) const
3037{
3038 return constImage()->gamma;
3039}
3040
3041Magick::Geometry Magick::Image::geometry ( void ) const
3042{
3043 if ( constImage()->geometry )
3044 {
3045 return Geometry(constImage()->geometry);
3046 }
3047
3048 throwExceptionExplicit( OptionWarning,
3049 "Image does not contain a geometry");
3050
3051 return Geometry();
3052}
3053
cristyeaedf062010-05-29 22:36:02 +00003054void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
cristy3ed852e2009-09-05 21:47:34 +00003055{
3056 modifyImage();
3057 image()->dispose = (DisposeType) disposeMethod_;
3058}
cristyeaedf062010-05-29 22:36:02 +00003059size_t Magick::Image::gifDisposeMethod ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003060{
3061 // FIXME: It would be better to return an enumeration
3062 return constImage()->dispose;
3063}
3064
3065// ICC ICM color profile (BLOB)
3066void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3067{
3068 profile("icm",colorProfile_);
3069}
3070Magick::Blob Magick::Image::iccColorProfile( void ) const
3071{
3072 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3073 if ( color_profile == (StringInfo *) NULL)
3074 return Blob( 0, 0 );
3075 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3076}
3077
3078void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3079{
3080 modifyImage();
3081 image()->interlace = interlace_;
3082 options()->interlaceType ( interlace_ );
3083}
3084Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3085{
3086 return constImage()->interlace;
3087}
3088
3089// IPTC profile (BLOB)
3090void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3091{
3092 modifyImage();
3093 if ( iptcProfile_.data() != 0 )
3094 {
3095 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3096 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3097 (void) SetImageProfile( image(), "iptc", iptc_profile);
3098 iptc_profile =DestroyStringInfo( iptc_profile );
3099 }
3100}
3101Magick::Blob Magick::Image::iptcProfile( void ) const
3102{
3103 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3104 if ( iptc_profile == (StringInfo *) NULL)
3105 return Blob( 0, 0 );
3106 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3107}
3108
3109// Does object contain valid image?
3110void Magick::Image::isValid ( const bool isValid_ )
3111{
3112 if ( !isValid_ )
3113 {
3114 delete _imgRef;
3115 _imgRef = new ImageRef;
3116 }
3117 else if ( !isValid() )
3118 {
3119 // Construct with single-pixel black image to make
3120 // image valid. This is an obvious hack.
3121 size( Geometry(1,1) );
3122 read( "xc:#000000" );
3123 }
3124}
3125
3126bool Magick::Image::isValid ( void ) const
3127{
3128 if ( rows() && columns() )
3129 return true;
3130
3131 return false;
3132}
3133
3134// Label image
3135void Magick::Image::label ( const std::string &label_ )
3136{
3137 modifyImage();
3138 SetImageProperty ( image(), "Label", NULL );
3139 if ( label_.length() > 0 )
3140 SetImageProperty ( image(), "Label", label_.c_str() );
3141 throwImageException();
3142}
3143std::string Magick::Image::label ( void ) const
3144{
3145 const char *value = GetImageProperty( constImage(), "Label" );
3146
3147 if ( value )
3148 return std::string( value );
3149
3150 return std::string();
3151}
3152
3153void Magick::Image::magick ( const std::string &magick_ )
3154{
3155 modifyImage();
3156
3157 magick_.copy( image()->magick,
3158 sizeof(image()->magick) - 1 );
3159 image()->magick[ magick_.length() ] = 0;
3160
3161 options()->magick( magick_ );
3162}
3163std::string Magick::Image::magick ( void ) const
3164{
3165 if ( *(constImage()->magick) != '\0' )
3166 return std::string(constImage()->magick);
3167
3168 return constOptions()->magick( );
3169}
3170
3171void Magick::Image::matte ( const bool matteFlag_ )
3172{
3173 modifyImage();
3174
3175 // If matte channel is requested, but image doesn't already have a
3176 // matte channel, then create an opaque matte channel. Likewise, if
3177 // the image already has a matte channel but a matte channel is not
3178 // desired, then set the matte channel to opaque.
3179 if ((matteFlag_ && !constImage()->matte) ||
3180 (constImage()->matte && !matteFlag_))
cristy4c08aed2011-07-01 19:47:50 +00003181 SetImageOpacity(image(),OpaqueAlpha);
cristy3ed852e2009-09-05 21:47:34 +00003182
3183 image()->matte = (MagickBooleanType) matteFlag_;
3184}
3185bool Magick::Image::matte ( void ) const
3186{
3187 if ( constImage()->matte )
3188 return true;
3189 else
3190 return false;
3191}
3192
3193void Magick::Image::matteColor ( const Color &matteColor_ )
3194{
3195 modifyImage();
3196
3197 if ( matteColor_.isValid() )
3198 {
cristy391f1ce2010-09-09 17:23:28 +00003199 image()->matte_color = matteColor_;
3200 options()->matteColor( matteColor_ );
cristy3ed852e2009-09-05 21:47:34 +00003201 }
3202 else
3203 {
3204 // Set to default matte color
3205 Color tmpColor( "#BDBDBD" );
cristy391f1ce2010-09-09 17:23:28 +00003206 image()->matte_color = tmpColor;
cristy3ed852e2009-09-05 21:47:34 +00003207 options()->matteColor( tmpColor );
3208 }
3209}
3210Magick::Color Magick::Image::matteColor ( void ) const
3211{
3212 return Color( constImage()->matte_color.red,
3213 constImage()->matte_color.green,
cristy391f1ce2010-09-09 17:23:28 +00003214 constImage()->matte_color.blue );
cristy3ed852e2009-09-05 21:47:34 +00003215}
3216
3217double Magick::Image::meanErrorPerPixel ( void ) const
3218{
3219 return(constImage()->error.mean_error_per_pixel);
3220}
3221
3222// Image modulus depth (minimum number of bits required to support
3223// red/green/blue components without loss of accuracy)
cristyeaedf062010-05-29 22:36:02 +00003224void Magick::Image::modulusDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00003225{
3226 modifyImage();
3227 SetImageDepth( image(), depth_ );
3228 options()->depth( depth_ );
3229}
cristyeaedf062010-05-29 22:36:02 +00003230size_t Magick::Image::modulusDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003231{
3232 ExceptionInfo exceptionInfo;
3233 GetExceptionInfo( &exceptionInfo );
cristyeaedf062010-05-29 22:36:02 +00003234 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003235 throwException( exceptionInfo );
3236 (void) DestroyExceptionInfo( &exceptionInfo );
3237 return depth;
3238}
3239
3240void Magick::Image::monochrome ( const bool monochromeFlag_ )
3241{
3242 modifyImage();
3243 options()->monochrome( monochromeFlag_ );
3244}
3245bool Magick::Image::monochrome ( void ) const
3246{
3247 return constOptions()->monochrome( );
3248}
3249
3250Magick::Geometry Magick::Image::montageGeometry ( void ) const
3251{
3252 if ( constImage()->montage )
3253 return Magick::Geometry(constImage()->montage);
3254
3255 throwExceptionExplicit( CorruptImageWarning,
3256 "Image does not contain a montage" );
3257
3258 return Magick::Geometry();
3259}
3260
3261double Magick::Image::normalizedMaxError ( void ) const
3262{
3263 return(constImage()->error.normalized_maximum_error);
3264}
3265
3266double Magick::Image::normalizedMeanError ( void ) const
3267{
3268 return constImage()->error.normalized_mean_error;
3269}
3270
3271// Image orientation
3272void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3273{
3274 modifyImage();
3275 image()->orientation = orientation_;
3276}
3277Magick::OrientationType Magick::Image::orientation ( void ) const
3278{
3279 return constImage()->orientation;
3280}
3281
3282void Magick::Image::penColor ( const Color &penColor_ )
3283{
3284 modifyImage();
3285 options()->fillColor(penColor_);
3286 options()->strokeColor(penColor_);
3287}
3288Magick::Color Magick::Image::penColor ( void ) const
3289{
3290 return constOptions()->fillColor();
3291}
3292
3293void Magick::Image::penTexture ( const Image &penTexture_ )
3294{
3295 modifyImage();
3296 if(penTexture_.isValid())
3297 options()->fillPattern( penTexture_.constImage() );
3298 else
3299 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3300}
3301
3302Magick::Image Magick::Image::penTexture ( void ) const
3303{
3304 // FIXME: This is inordinately innefficient
3305 Image texture;
3306
3307 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3308
3309 if ( tmpTexture )
3310 {
3311 ExceptionInfo exceptionInfo;
3312 GetExceptionInfo( &exceptionInfo );
3313 MagickCore::Image* image =
3314 CloneImage( tmpTexture,
3315 0, // columns
3316 0, // rows
3317 MagickTrue, // orphan
3318 &exceptionInfo);
3319 texture.replaceImage( image );
3320 throwException( exceptionInfo );
3321 (void) DestroyExceptionInfo( &exceptionInfo );
3322 }
3323 return texture;
3324}
3325
3326// Set the color of a pixel.
cristy35ef8242010-06-03 16:24:13 +00003327void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00003328 const Color &color_ )
3329{
3330 // Test arguments to ensure they are within the image.
cristy07fb9182010-06-06 23:37:14 +00003331 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
cristy3ed852e2009-09-05 21:47:34 +00003332 throwExceptionExplicit( OptionError,
3333 "Access outside of image boundary" );
3334
3335 modifyImage();
3336
3337 // Set image to DirectClass
3338 classType( DirectClass );
3339
3340 // Get pixel view
3341 Pixels pixels(*this);
3342 // Set pixel value
cristy4c08aed2011-07-01 19:47:50 +00003343 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3344 PixelPacket packet = color_;
3345 MagickCore::SetPixelPacket(constImage(),&packet,pixel);
cristy3ed852e2009-09-05 21:47:34 +00003346 // Tell ImageMagick that pixels have been updated
3347 pixels.sync();
3348
3349 return;
3350}
3351
3352// Get the color of a pixel
cristy35ef8242010-06-03 16:24:13 +00003353Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3354 const ssize_t y_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003355{
3356 ClassType storage_class;
3357 storage_class = classType();
3358 // DirectClass
cristy4c08aed2011-07-01 19:47:50 +00003359 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3360 if ( pixel )
cristy3ed852e2009-09-05 21:47:34 +00003361 {
cristy4c08aed2011-07-01 19:47:50 +00003362 PixelPacket packet;
3363 MagickCore::GetPixelPacket(constImage(),pixel,&packet);
3364 return Color( packet );
cristy3ed852e2009-09-05 21:47:34 +00003365 }
3366
3367 return Color(); // invalid
3368}
3369
3370// Preferred size and location of an image canvas.
3371void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3372{
3373 modifyImage();
3374 options()->page( pageSize_ );
3375 image()->page = pageSize_;
3376}
3377Magick::Geometry Magick::Image::page ( void ) const
3378{
3379 return Geometry( constImage()->page.width,
3380 constImage()->page.height,
3381 AbsoluteValue(constImage()->page.x),
3382 AbsoluteValue(constImage()->page.y),
3383 constImage()->page.x < 0 ? true : false,
3384 constImage()->page.y < 0 ? true : false);
3385}
3386
3387// Add a named profile to an image or remove a named profile by
3388// passing an empty Blob (use default Blob constructor).
3389// Valid names are:
3390// "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3391void Magick::Image::profile( const std::string name_,
3392 const Magick::Blob &profile_ )
3393{
3394 modifyImage();
cristyd99b0962010-05-29 23:14:26 +00003395 ssize_t result = ProfileImage( image(), name_.c_str(),
cristy3ed852e2009-09-05 21:47:34 +00003396 (unsigned char *)profile_.data(),
3397 profile_.length(), MagickTrue);
3398
3399 if( !result )
3400 throwImageException();
3401}
3402
3403// Retrieve a named profile from the image.
3404// Valid names are:
3405// "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3406// an existing generic profile name.
3407Magick::Blob Magick::Image::profile( const std::string name_ ) const
3408{
3409 const MagickCore::Image* image = constImage();
3410
3411 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3412
3413 if ( profile != (StringInfo *) NULL)
3414 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3415
3416 Blob blob;
3417 Image temp_image = *this;
3418 temp_image.write( &blob, name_ );
3419 return blob;
3420}
3421
cristyeaedf062010-05-29 22:36:02 +00003422void Magick::Image::quality ( const size_t quality_ )
cristy3ed852e2009-09-05 21:47:34 +00003423{
3424 modifyImage();
3425 image()->quality = quality_;
3426 options()->quality( quality_ );
3427}
cristyeaedf062010-05-29 22:36:02 +00003428size_t Magick::Image::quality ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003429{
3430 return constImage()->quality;
3431}
3432
cristyeaedf062010-05-29 22:36:02 +00003433void Magick::Image::quantizeColors ( const size_t colors_ )
cristy3ed852e2009-09-05 21:47:34 +00003434{
3435 modifyImage();
3436 options()->quantizeColors( colors_ );
3437}
cristyeaedf062010-05-29 22:36:02 +00003438size_t Magick::Image::quantizeColors ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003439{
3440 return constOptions()->quantizeColors( );
3441}
3442
3443void Magick::Image::quantizeColorSpace
3444 ( const Magick::ColorspaceType colorSpace_ )
3445{
3446 modifyImage();
3447 options()->quantizeColorSpace( colorSpace_ );
3448}
3449Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3450{
3451 return constOptions()->quantizeColorSpace( );
3452}
3453
3454void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3455{
3456 modifyImage();
3457 options()->quantizeDither( ditherFlag_ );
3458}
3459bool Magick::Image::quantizeDither ( void ) const
3460{
3461 return constOptions()->quantizeDither( );
3462}
3463
cristyeaedf062010-05-29 22:36:02 +00003464void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
cristy3ed852e2009-09-05 21:47:34 +00003465{
3466 modifyImage();
3467 options()->quantizeTreeDepth( treeDepth_ );
3468}
cristyeaedf062010-05-29 22:36:02 +00003469size_t Magick::Image::quantizeTreeDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003470{
3471 return constOptions()->quantizeTreeDepth( );
3472}
3473
3474void Magick::Image::renderingIntent
3475 ( const Magick::RenderingIntent renderingIntent_ )
3476{
3477 modifyImage();
3478 image()->rendering_intent = renderingIntent_;
3479}
3480Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3481{
3482 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3483}
3484
3485void Magick::Image::resolutionUnits
3486 ( const Magick::ResolutionType resolutionUnits_ )
3487{
3488 modifyImage();
3489 image()->units = resolutionUnits_;
3490 options()->resolutionUnits( resolutionUnits_ );
3491}
3492Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3493{
3494 return constOptions()->resolutionUnits( );
3495}
3496
cristyeaedf062010-05-29 22:36:02 +00003497void Magick::Image::scene ( const size_t scene_ )
cristy3ed852e2009-09-05 21:47:34 +00003498{
3499 modifyImage();
3500 image()->scene = scene_;
3501}
cristyeaedf062010-05-29 22:36:02 +00003502size_t Magick::Image::scene ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003503{
3504 return constImage()->scene;
3505}
3506
3507std::string Magick::Image::signature ( const bool force_ ) const
3508{
3509 Lock( &_imgRef->_mutexLock );
3510
3511 // Re-calculate image signature if necessary
3512 if ( force_ ||
3513 !GetImageProperty(constImage(), "Signature") ||
3514 constImage()->taint )
3515 {
3516 SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
3517 }
3518
3519 const char *property = GetImageProperty(constImage(), "Signature");
3520
3521 return std::string( property );
3522}
3523
3524void Magick::Image::size ( const Geometry &geometry_ )
3525{
3526 modifyImage();
3527 options()->size( geometry_ );
3528 image()->rows = geometry_.height();
3529 image()->columns = geometry_.width();
3530}
3531Magick::Geometry Magick::Image::size ( void ) const
3532{
3533 return Magick::Geometry( constImage()->columns, constImage()->rows );
3534}
3535
cristy8198a752009-09-28 23:59:24 +00003536// Splice image
3537void Magick::Image::splice( const Geometry &geometry_ )
3538{
3539 RectangleInfo spliceInfo = geometry_;
3540 ExceptionInfo exceptionInfo;
3541 GetExceptionInfo( &exceptionInfo );
3542 MagickCore::Image* newImage =
3543 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3544 replaceImage( newImage );
3545 throwException( exceptionInfo );
3546 (void) DestroyExceptionInfo( &exceptionInfo );
3547}
3548
cristy3ed852e2009-09-05 21:47:34 +00003549// Obtain image statistics. Statistics are normalized to the range of
3550// 0.0 to 1.0 and are output to the specified ImageStatistics
3551// structure.
3552void Magick::Image::statistics ( ImageStatistics *statistics ) const
3553{
3554 double
3555 maximum,
3556 minimum;
3557
3558 ExceptionInfo exceptionInfo;
3559 GetExceptionInfo( &exceptionInfo );
3560 (void) GetImageChannelRange(constImage(),RedChannel,&minimum,&maximum,
3561 &exceptionInfo);
3562 statistics->red.minimum=minimum;
3563 statistics->red.maximum=maximum;
3564 (void) GetImageChannelMean(constImage(),RedChannel,
3565 &statistics->red.mean,&statistics->red.standard_deviation,&exceptionInfo);
3566 (void) GetImageChannelKurtosis(constImage(),RedChannel,
3567 &statistics->red.kurtosis,&statistics->red.skewness,&exceptionInfo);
3568 (void) GetImageChannelRange(constImage(),GreenChannel,&minimum,&maximum,
3569 &exceptionInfo);
3570 statistics->green.minimum=minimum;
3571 statistics->green.maximum=maximum;
3572 (void) GetImageChannelMean(constImage(),GreenChannel,
3573 &statistics->green.mean,&statistics->green.standard_deviation,
3574 &exceptionInfo);
3575 (void) GetImageChannelKurtosis(constImage(),GreenChannel,
3576 &statistics->green.kurtosis,&statistics->green.skewness,&exceptionInfo);
3577 (void) GetImageChannelRange(constImage(),BlueChannel,&minimum,&maximum,
3578 &exceptionInfo);
3579 statistics->blue.minimum=minimum;
3580 statistics->blue.maximum=maximum;
3581 (void) GetImageChannelMean(constImage(),BlueChannel,
3582 &statistics->blue.mean,&statistics->blue.standard_deviation,&exceptionInfo);
3583 (void) GetImageChannelKurtosis(constImage(),BlueChannel,
3584 &statistics->blue.kurtosis,&statistics->blue.skewness,&exceptionInfo);
3585 (void) GetImageChannelRange(constImage(),OpacityChannel,&minimum,&maximum,
3586 &exceptionInfo);
cristy4c08aed2011-07-01 19:47:50 +00003587 statistics->alpha.minimum=minimum;
3588 statistics->alpha.maximum=maximum;
cristy3ed852e2009-09-05 21:47:34 +00003589 (void) GetImageChannelMean(constImage(),OpacityChannel,
cristy4c08aed2011-07-01 19:47:50 +00003590 &statistics->alpha.mean,&statistics->alpha.standard_deviation,
cristy3ed852e2009-09-05 21:47:34 +00003591 &exceptionInfo);
3592 (void) GetImageChannelKurtosis(constImage(),OpacityChannel,
cristy4c08aed2011-07-01 19:47:50 +00003593 &statistics->alpha.kurtosis,&statistics->alpha.skewness,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003594 throwException( exceptionInfo );
3595 (void) DestroyExceptionInfo( &exceptionInfo );
3596}
3597
cristy9f89a3f2011-02-12 17:02:35 +00003598// Strip strips an image of all profiles and comments.
3599void Magick::Image::strip ( void )
3600{
3601 modifyImage();
3602 StripImage( image() );
3603 throwImageException();
3604}
3605
cristy3ed852e2009-09-05 21:47:34 +00003606// enabled/disable stroke anti-aliasing
3607void Magick::Image::strokeAntiAlias ( const bool flag_ )
3608{
3609 modifyImage();
3610 options()->strokeAntiAlias(flag_);
3611}
3612bool Magick::Image::strokeAntiAlias ( void ) const
3613{
3614 return constOptions()->strokeAntiAlias();
3615}
3616
3617// Color to use when drawing object outlines
3618void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3619{
3620 modifyImage();
3621 options()->strokeColor(strokeColor_);
3622}
3623Magick::Color Magick::Image::strokeColor ( void ) const
3624{
3625 return constOptions()->strokeColor();
3626}
3627
3628// dash pattern for drawing vector objects (default one)
3629void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3630{
3631 modifyImage();
3632 options()->strokeDashArray( strokeDashArray_ );
3633}
3634
3635const double* Magick::Image::strokeDashArray ( void ) const
3636{
3637 return constOptions()->strokeDashArray( );
3638}
3639
3640// dash offset for drawing vector objects (default one)
3641void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3642{
3643 modifyImage();
3644 options()->strokeDashOffset( strokeDashOffset_ );
3645}
3646
3647double Magick::Image::strokeDashOffset ( void ) const
3648{
3649 return constOptions()->strokeDashOffset( );
3650}
3651
3652// Specify the shape to be used at the end of open subpaths when they
3653// are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3654// and SquareCap.
3655void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3656{
3657 modifyImage();
3658 options()->strokeLineCap( lineCap_ );
3659}
3660Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3661{
3662 return constOptions()->strokeLineCap( );
3663}
3664
3665// Specify the shape to be used at the corners of paths (or other
3666// vector shapes) when they are stroked. Values of LineJoin are
3667// UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3668void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3669{
3670 modifyImage();
3671 options()->strokeLineJoin( lineJoin_ );
3672}
3673Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3674{
3675 return constOptions()->strokeLineJoin( );
3676}
3677
3678// Specify miter limit. When two line segments meet at a sharp angle
3679// and miter joins have been specified for 'lineJoin', it is possible
3680// for the miter to extend far beyond the thickness of the line
3681// stroking the path. The miterLimit' imposes a limit on the ratio of
3682// the miter length to the 'lineWidth'. The default value of this
3683// parameter is 4.
cristyeaedf062010-05-29 22:36:02 +00003684void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
cristy3ed852e2009-09-05 21:47:34 +00003685{
3686 modifyImage();
3687 options()->strokeMiterLimit( strokeMiterLimit_ );
3688}
cristyeaedf062010-05-29 22:36:02 +00003689size_t Magick::Image::strokeMiterLimit ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003690{
3691 return constOptions()->strokeMiterLimit( );
3692}
3693
3694// Pattern to use while stroking drawn objects.
3695void Magick::Image::strokePattern ( const Image &strokePattern_ )
3696{
3697 modifyImage();
3698 if(strokePattern_.isValid())
3699 options()->strokePattern( strokePattern_.constImage() );
3700 else
3701 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3702}
3703Magick::Image Magick::Image::strokePattern ( void ) const
3704{
3705 // FIXME: This is inordinately innefficient
3706 Image texture;
3707
3708 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3709
3710 if ( tmpTexture )
3711 {
3712 ExceptionInfo exceptionInfo;
3713 GetExceptionInfo( &exceptionInfo );
3714 MagickCore::Image* image =
3715 CloneImage( tmpTexture,
3716 0, // columns
3717 0, // rows
3718 MagickTrue, // orphan
3719 &exceptionInfo);
3720 throwException( exceptionInfo );
3721 (void) DestroyExceptionInfo( &exceptionInfo );
3722 texture.replaceImage( image );
3723 }
3724 return texture;
3725}
3726
3727// Stroke width for drawing lines, circles, ellipses, etc.
3728void Magick::Image::strokeWidth ( const double strokeWidth_ )
3729{
3730 modifyImage();
3731 options()->strokeWidth( strokeWidth_ );
3732}
3733double Magick::Image::strokeWidth ( void ) const
3734{
3735 return constOptions()->strokeWidth( );
3736}
3737
cristyeaedf062010-05-29 22:36:02 +00003738void Magick::Image::subImage ( const size_t subImage_ )
cristy3ed852e2009-09-05 21:47:34 +00003739{
3740 modifyImage();
3741 options()->subImage( subImage_ );
3742}
cristyeaedf062010-05-29 22:36:02 +00003743size_t Magick::Image::subImage ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003744{
3745 return constOptions()->subImage( );
3746}
3747
cristyeaedf062010-05-29 22:36:02 +00003748void Magick::Image::subRange ( const size_t subRange_ )
cristy3ed852e2009-09-05 21:47:34 +00003749{
3750 modifyImage();
3751 options()->subRange( subRange_ );
3752}
cristyeaedf062010-05-29 22:36:02 +00003753size_t Magick::Image::subRange ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003754{
3755 return constOptions()->subRange( );
3756}
3757
3758// Annotation text encoding (e.g. "UTF-16")
3759void Magick::Image::textEncoding ( const std::string &encoding_ )
3760{
3761 modifyImage();
3762 options()->textEncoding( encoding_ );
3763}
3764std::string Magick::Image::textEncoding ( void ) const
3765{
3766 return constOptions()->textEncoding( );
3767}
3768
cristybb503372010-05-27 20:51:26 +00003769size_t Magick::Image::totalColors ( void )
cristy3ed852e2009-09-05 21:47:34 +00003770{
3771 ExceptionInfo exceptionInfo;
3772 GetExceptionInfo( &exceptionInfo );
cristybb503372010-05-27 20:51:26 +00003773 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003774 throwException( exceptionInfo );
3775 (void) DestroyExceptionInfo( &exceptionInfo );
3776 return colors;
3777}
3778
3779// Origin of coordinate system to use when annotating with text or drawing
3780void Magick::Image::transformOrigin ( const double x_, const double y_ )
3781{
3782 modifyImage();
3783 options()->transformOrigin( x_, y_ );
3784}
3785
3786// Rotation to use when annotating with text or drawing
3787void Magick::Image::transformRotation ( const double angle_ )
3788{
3789 modifyImage();
3790 options()->transformRotation( angle_ );
3791}
3792
3793// Reset transformation parameters to default
3794void Magick::Image::transformReset ( void )
3795{
3796 modifyImage();
3797 options()->transformReset();
3798}
3799
3800// Scale to use when annotating with text or drawing
3801void Magick::Image::transformScale ( const double sx_, const double sy_ )
3802{
3803 modifyImage();
3804 options()->transformScale( sx_, sy_ );
3805}
3806
3807// Skew to use in X axis when annotating with text or drawing
3808void Magick::Image::transformSkewX ( const double skewx_ )
3809{
3810 modifyImage();
3811 options()->transformSkewX( skewx_ );
3812}
3813
3814// Skew to use in Y axis when annotating with text or drawing
3815void Magick::Image::transformSkewY ( const double skewy_ )
3816{
3817 modifyImage();
3818 options()->transformSkewY( skewy_ );
3819}
3820
3821// Image representation type
3822Magick::ImageType Magick::Image::type ( void ) const
3823{
3824
3825 ExceptionInfo exceptionInfo;
3826 GetExceptionInfo( &exceptionInfo );
3827 ImageType image_type = constOptions()->type();
3828 if ( image_type == UndefinedType )
3829 image_type= GetImageType( constImage(), &exceptionInfo);
3830 throwException( exceptionInfo );
3831 (void) DestroyExceptionInfo( &exceptionInfo );
3832 return image_type;
3833}
3834void Magick::Image::type ( const Magick::ImageType type_)
3835{
3836 modifyImage();
3837 options()->type( type_ );
3838 SetImageType( image(), type_ );
3839}
3840
3841void Magick::Image::verbose ( const bool verboseFlag_ )
3842{
3843 modifyImage();
3844 options()->verbose( verboseFlag_ );
3845}
3846bool Magick::Image::verbose ( void ) const
3847{
3848 return constOptions()->verbose( );
3849}
3850
3851void Magick::Image::view ( const std::string &view_ )
3852{
3853 modifyImage();
3854 options()->view( view_ );
3855}
3856std::string Magick::Image::view ( void ) const
3857{
3858 return constOptions()->view( );
3859}
3860
3861// Virtual pixel method
3862void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
3863{
3864 modifyImage();
3865 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
3866 options()->virtualPixelMethod( virtual_pixel_method_ );
3867}
3868Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
3869{
3870 return GetImageVirtualPixelMethod( constImage() );
3871}
3872
3873void Magick::Image::x11Display ( const std::string &display_ )
3874{
3875 modifyImage();
3876 options()->x11Display( display_ );
3877}
3878std::string Magick::Image::x11Display ( void ) const
3879{
3880 return constOptions()->x11Display( );
3881}
3882
3883double Magick::Image::xResolution ( void ) const
3884{
3885 return constImage()->x_resolution;
3886}
3887double Magick::Image::yResolution ( void ) const
3888{
3889 return constImage()->y_resolution;
3890}
3891
3892// Copy Constructor
3893Magick::Image::Image( const Image & image_ )
3894 : _imgRef(image_._imgRef)
3895{
3896 Lock( &_imgRef->_mutexLock );
3897
3898 // Increase reference count
3899 ++_imgRef->_refCount;
3900}
3901
3902// Assignment operator
3903Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
3904{
3905 if( this != &image_ )
3906 {
3907 {
3908 Lock( &image_._imgRef->_mutexLock );
3909 ++image_._imgRef->_refCount;
3910 }
3911
3912 bool doDelete = false;
3913 {
3914 Lock( &_imgRef->_mutexLock );
3915 if ( --_imgRef->_refCount == 0 )
3916 doDelete = true;
3917 }
3918
3919 if ( doDelete )
3920 {
3921 // Delete old image reference with associated image and options.
3922 delete _imgRef;
3923 _imgRef = 0;
3924 }
3925 // Use new image reference
3926 _imgRef = image_._imgRef;
3927 }
3928
3929 return *this;
3930}
3931
3932//////////////////////////////////////////////////////////////////////
3933//
3934// Low-level Pixel Access Routines
3935//
3936// Also see the Pixels class, which provides support for multiple
3937// cache views. The low-level pixel access routines in the Image
3938// class are provided in order to support backward compatability.
3939//
3940//////////////////////////////////////////////////////////////////////
3941
3942// Transfers read-only pixels from the image to the pixel cache as
3943// defined by the specified region
cristy4c08aed2011-07-01 19:47:50 +00003944const Magick::Quantum* Magick::Image::getConstPixels
cristyd99b0962010-05-29 23:14:26 +00003945 ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00003946 const size_t columns_,
3947 const size_t rows_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003948{
3949 ExceptionInfo exceptionInfo;
3950 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00003951 const Quantum* p = (*GetVirtualPixels)( constImage(),
cristy3ed852e2009-09-05 21:47:34 +00003952 x_, y_,
3953 columns_, rows_,
3954 &exceptionInfo );
3955 throwException( exceptionInfo );
3956 (void) DestroyExceptionInfo( &exceptionInfo );
3957 return p;
3958}
3959
cristy4c08aed2011-07-01 19:47:50 +00003960// Obtain read-only pixel associated pixels channels
3961const void* Magick::Image::getConstMetacontent ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003962{
cristy4c08aed2011-07-01 19:47:50 +00003963 const void* result = GetVirtualMetacontent( constImage() );
cristy3ed852e2009-09-05 21:47:34 +00003964
3965 if( !result )
3966 throwImageException();
3967
3968 return result;
3969}
3970
cristy4c08aed2011-07-01 19:47:50 +00003971// Obtain image pixel associated pixels channels
3972void* Magick::Image::getMetacontent ( void )
cristy3ed852e2009-09-05 21:47:34 +00003973{
cristy4c08aed2011-07-01 19:47:50 +00003974 void* result = GetAuthenticMetacontent( image() );
cristy3ed852e2009-09-05 21:47:34 +00003975
3976 if( !result )
3977 throwImageException();
3978
3979 return ( result );
3980}
3981
3982// Transfers pixels from the image to the pixel cache as defined
3983// by the specified region. Modified pixels may be subsequently
3984// transferred back to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00003985Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00003986 const size_t columns_,
3987 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00003988{
3989 modifyImage();
3990 ExceptionInfo exceptionInfo;
3991 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00003992 Quantum* result = (*GetAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00003993 x_, y_,
3994 columns_, rows_, &exceptionInfo );
3995 throwException( exceptionInfo );
3996 (void) DestroyExceptionInfo( &exceptionInfo );
3997
3998 return result;
3999}
4000
4001// Allocates a pixel cache region to store image pixels as defined
4002// by the region rectangle. This area is subsequently transferred
4003// from the pixel cache to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00004004Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00004005 const size_t columns_,
4006 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00004007{
4008 modifyImage();
4009 ExceptionInfo exceptionInfo;
4010 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00004011 Quantum* result = (*QueueAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00004012 x_, y_,
4013 columns_, rows_, &exceptionInfo );
4014 throwException( exceptionInfo );
4015 (void) DestroyExceptionInfo( &exceptionInfo );
4016
4017 return result;
4018}
4019
4020// Transfers the image cache pixels to the image.
4021void Magick::Image::syncPixels ( void )
4022{
4023 ExceptionInfo exceptionInfo;
4024 GetExceptionInfo( &exceptionInfo );
4025 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4026 throwException( exceptionInfo );
4027 (void) DestroyExceptionInfo( &exceptionInfo );
4028}
4029
4030// Transfers one or more pixel components from a buffer or file
4031// into the image pixel cache of an image.
4032// Used to support image decoders.
4033void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4034 const unsigned char *source_ )
4035{
4036 QuantumInfo
4037 *quantum_info;
4038
4039 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4040 ExceptionInfo exceptionInfo;
4041 GetExceptionInfo( &exceptionInfo );
4042 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4043 quantum_,source_, &exceptionInfo);
4044 throwException( exceptionInfo );
4045 (void) DestroyExceptionInfo( &exceptionInfo );
4046 quantum_info=DestroyQuantumInfo(quantum_info);
4047}
4048
4049// Transfers one or more pixel components from the image pixel
4050// cache to a buffer or file.
4051// Used to support image encoders.
4052void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4053 unsigned char *destination_ )
4054{
4055 QuantumInfo
4056 *quantum_info;
4057
4058 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4059 ExceptionInfo exceptionInfo;
4060 GetExceptionInfo( &exceptionInfo );
4061 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4062 quantum_,destination_, &exceptionInfo);
4063 quantum_info=DestroyQuantumInfo(quantum_info);
4064 throwException( exceptionInfo );
4065 (void) DestroyExceptionInfo( &exceptionInfo );
4066}
4067
4068/////////////////////////////////////////////////////////////////////
4069//
4070// No end-user methods beyond this point
4071//
4072/////////////////////////////////////////////////////////////////////
4073
4074
4075//
4076// Construct using existing image and default options
4077//
4078Magick::Image::Image ( MagickCore::Image* image_ )
4079 : _imgRef(new ImageRef( image_))
4080{
4081}
4082
4083// Get Magick::Options*
4084Magick::Options* Magick::Image::options( void )
4085{
4086 return _imgRef->options();
4087}
4088const Magick::Options* Magick::Image::constOptions( void ) const
4089{
4090 return _imgRef->options();
4091}
4092
4093// Get MagickCore::Image*
4094MagickCore::Image*& Magick::Image::image( void )
4095{
4096 return _imgRef->image();
4097}
4098const MagickCore::Image* Magick::Image::constImage( void ) const
4099{
4100 return _imgRef->image();
4101}
4102
4103// Get ImageInfo *
4104MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4105{
4106 return _imgRef->options()->imageInfo();
4107}
4108const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4109{
4110 return _imgRef->options()->imageInfo();
4111}
4112
4113// Get QuantizeInfo *
4114MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4115{
4116 return _imgRef->options()->quantizeInfo();
4117}
4118const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4119{
4120 return _imgRef->options()->quantizeInfo();
4121}
4122
4123//
4124// Replace current image
4125//
4126MagickCore::Image * Magick::Image::replaceImage
4127 ( MagickCore::Image* replacement_ )
4128{
4129 MagickCore::Image* image;
4130
4131 if( replacement_ )
4132 image = replacement_;
4133 else
4134 image = AcquireImage(constImageInfo());
4135
4136 {
4137 Lock( &_imgRef->_mutexLock );
4138
4139 if ( _imgRef->_refCount == 1 )
4140 {
4141 // We own the image, just replace it, and de-register
4142 _imgRef->id( -1 );
4143 _imgRef->image(image);
4144 }
4145 else
4146 {
4147 // We don't own the image, dereference and replace with copy
4148 --_imgRef->_refCount;
4149 _imgRef = new ImageRef( image, constOptions() );
4150 }
4151 }
4152
4153 return _imgRef->_image;
4154}
4155
4156//
4157// Prepare to modify image or image options
4158// Replace current image and options with copy if reference count > 1
4159//
4160void Magick::Image::modifyImage( void )
4161{
4162 {
4163 Lock( &_imgRef->_mutexLock );
4164 if ( _imgRef->_refCount == 1 )
4165 {
4166 // De-register image and return
4167 _imgRef->id( -1 );
4168 return;
4169 }
4170 }
4171
4172 ExceptionInfo exceptionInfo;
4173 GetExceptionInfo( &exceptionInfo );
4174 replaceImage( CloneImage( image(),
4175 0, // columns
4176 0, // rows
4177 MagickTrue, // orphan
4178 &exceptionInfo) );
4179 throwException( exceptionInfo );
4180 (void) DestroyExceptionInfo( &exceptionInfo );
4181 return;
4182}
4183
4184//
4185// Test for an ImageMagick reported error and throw exception if one
4186// has been reported. Secretly resets image->exception back to default
4187// state even though this method is const.
4188//
4189void Magick::Image::throwImageException( void ) const
4190{
4191 // Throw C++ exception while resetting Image exception to default state
4192 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4193}
4194
4195// Register image with image registry or obtain registration id
cristybb503372010-05-27 20:51:26 +00004196ssize_t Magick::Image::registerId( void )
cristy3ed852e2009-09-05 21:47:34 +00004197{
4198 Lock( &_imgRef->_mutexLock );
4199 if( _imgRef->id() < 0 )
4200 {
4201 char id[MaxTextExtent];
4202 ExceptionInfo exceptionInfo;
4203 GetExceptionInfo( &exceptionInfo );
4204 _imgRef->id(_imgRef->id()+1);
cristye8c25f92010-06-03 00:53:06 +00004205 sprintf(id,"%.20g\n",(double) _imgRef->id());
cristy3ed852e2009-09-05 21:47:34 +00004206 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4207 throwException( exceptionInfo );
4208 (void) DestroyExceptionInfo( &exceptionInfo );
4209 }
4210 return _imgRef->id();
4211}
4212
4213// Unregister image from image registry
4214void Magick::Image::unregisterId( void )
4215{
4216 modifyImage();
4217 _imgRef->id( -1 );
4218}
4219
4220//
4221// Create a local wrapper around MagickCoreTerminus
4222//
4223namespace Magick
4224{
4225 extern "C" {
4226 void MagickPlusPlusDestroyMagick(void);
4227 }
4228}
4229
4230void Magick::MagickPlusPlusDestroyMagick(void)
4231{
4232 if (magick_initialized)
4233 {
4234 magick_initialized=false;
4235 MagickCore::MagickCoreTerminus();
4236 }
4237}
4238
4239// C library initialization routine
4240void MagickDLLDecl Magick::InitializeMagick(const char *path_)
4241{
4242 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4243 if (!magick_initialized)
4244 magick_initialized=true;
4245}
4246
4247//
4248// Cleanup class to ensure that ImageMagick singletons are destroyed
4249// so as to avoid any resemblence to a memory leak (which seems to
4250// confuse users)
4251//
4252namespace Magick
4253{
4254
4255 class MagickCleanUp
4256 {
4257 public:
4258 MagickCleanUp( void );
4259 ~MagickCleanUp( void );
4260 };
4261
4262 // The destructor for this object is invoked when the destructors for
4263 // static objects in this translation unit are invoked.
4264 static MagickCleanUp magickCleanUpGuard;
4265}
4266
4267Magick::MagickCleanUp::MagickCleanUp ( void )
4268{
4269 // Don't even think about invoking InitializeMagick here!
4270}
4271
4272Magick::MagickCleanUp::~MagickCleanUp ( void )
4273{
4274 MagickPlusPlusDestroyMagick();
4275}