blob: f160085bde8683f5f08ad90830133ef46972e4a4 [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();
cristy3139dc22011-07-08 00:11:42 +0000523 PushPixelComponentMap( image(), channel_ );
524 SeparateImage ( image() );
525 PopPixelComponentMap( image() );
cristy3ed852e2009-09-05 21:47:34 +0000526 throwImageException();
527}
528
529// Set or obtain modulus channel depth
cristyfefab1b2011-07-05 00:33:22 +0000530void Magick::Image::channelDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +0000531{
532 modifyImage();
cristyfefab1b2011-07-05 00:33:22 +0000533 SetImageDepth( image(), depth_);
cristy3ed852e2009-09-05 21:47:34 +0000534 throwImageException();
535}
cristyfefab1b2011-07-05 00:33:22 +0000536size_t Magick::Image::channelDepth ( )
cristy3ed852e2009-09-05 21:47:34 +0000537{
cristyeaedf062010-05-29 22:36:02 +0000538 size_t channel_depth;
cristy3ed852e2009-09-05 21:47:34 +0000539
540 ExceptionInfo exceptionInfo;
541 GetExceptionInfo( &exceptionInfo );
cristyfefab1b2011-07-05 00:33:22 +0000542 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000543 throwException( exceptionInfo );
544 (void) DestroyExceptionInfo( &exceptionInfo );
545 return channel_depth;
546}
547
548
549// Charcoal-effect image
550void Magick::Image::charcoal( const double radius_, const double sigma_ )
551{
552 ExceptionInfo exceptionInfo;
553 GetExceptionInfo( &exceptionInfo );
554 MagickCore::Image* newImage =
555 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
556 replaceImage( newImage );
557 throwException( exceptionInfo );
558 (void) DestroyExceptionInfo( &exceptionInfo );
559}
560
561// Chop image
562void Magick::Image::chop( const Geometry &geometry_ )
563{
564 RectangleInfo chopInfo = geometry_;
565 ExceptionInfo exceptionInfo;
566 GetExceptionInfo( &exceptionInfo );
567 MagickCore::Image* newImage =
568 ChopImage( image(), &chopInfo, &exceptionInfo);
569 replaceImage( newImage );
570 throwException( exceptionInfo );
571 (void) DestroyExceptionInfo( &exceptionInfo );
572}
573
cristyb32b90a2009-09-07 21:45:48 +0000574// contains one or more color corrections and applies the correction to the
575// image.
576void Magick::Image::cdl ( const std::string &cdl_ )
577{
578 modifyImage();
579 (void) ColorDecisionListImage( image(), cdl_.c_str() );
580 throwImageException();
581}
582
cristy3ed852e2009-09-05 21:47:34 +0000583// Colorize
cristy4c08aed2011-07-01 19:47:50 +0000584void Magick::Image::colorize ( const unsigned int alphaRed_,
585 const unsigned int alphaGreen_,
586 const unsigned int alphaBlue_,
cristy3ed852e2009-09-05 21:47:34 +0000587 const Color &penColor_ )
588{
589 if ( !penColor_.isValid() )
590 {
591 throwExceptionExplicit( OptionError,
592 "Pen color argument is invalid");
593 }
594
cristy4c08aed2011-07-01 19:47:50 +0000595 char alpha[MaxTextExtent];
596 FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
cristy3ed852e2009-09-05 21:47:34 +0000597
598 ExceptionInfo exceptionInfo;
599 GetExceptionInfo( &exceptionInfo );
600 MagickCore::Image* newImage =
cristy4c08aed2011-07-01 19:47:50 +0000601 ColorizeImage ( image(), alpha,
cristy3ed852e2009-09-05 21:47:34 +0000602 penColor_, &exceptionInfo );
603 replaceImage( newImage );
604 throwException( exceptionInfo );
605 (void) DestroyExceptionInfo( &exceptionInfo );
606}
cristy4c08aed2011-07-01 19:47:50 +0000607void Magick::Image::colorize ( const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000608 const Color &penColor_ )
609{
cristy4c08aed2011-07-01 19:47:50 +0000610 colorize( alpha_, alpha_, alpha_, penColor_ );
cristy3ed852e2009-09-05 21:47:34 +0000611}
612
cristy735e8942010-04-02 20:32:57 +0000613// Apply a color matrix to the image channels. The user supplied
614// matrix may be of order 1 to 6 (1x1 through 6x6).
cristyeaedf062010-05-29 22:36:02 +0000615void Magick::Image::colorMatrix (const size_t order_,
cristyc8918bb2010-04-03 01:57:27 +0000616 const double *color_matrix_)
cristy735e8942010-04-02 20:32:57 +0000617{
cristyc8918bb2010-04-03 01:57:27 +0000618 KernelInfo
619 *kernel_info;
620
cristy735e8942010-04-02 20:32:57 +0000621 ExceptionInfo exceptionInfo;
622 GetExceptionInfo( &exceptionInfo );
cristyc8918bb2010-04-03 01:57:27 +0000623 kernel_info=AcquireKernelInfo("1");
624 kernel_info->width=order_;
625 kernel_info->height=order_;
cristyc8918bb2010-04-03 01:57:27 +0000626 kernel_info->values=(double *) color_matrix_;
cristy735e8942010-04-02 20:32:57 +0000627 MagickCore::Image* newImage =
cristyc8918bb2010-04-03 01:57:27 +0000628 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
cristya2175d32010-04-03 02:25:17 +0000629 kernel_info->values=(double *) NULL;
cristyc8918bb2010-04-03 01:57:27 +0000630 kernel_info=DestroyKernelInfo(kernel_info);
cristy735e8942010-04-02 20:32:57 +0000631 replaceImage( newImage );
632 throwException( exceptionInfo );
633 (void) DestroyExceptionInfo( &exceptionInfo );
634}
635
cristy3ed852e2009-09-05 21:47:34 +0000636// Compare current image with another image
637// Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
638// in the current image. False is returned if the images are identical.
639bool Magick::Image::compare ( const Image &reference_ )
640{
641 modifyImage();
642 Image ref = reference_;
643 ref.modifyImage();
644 return static_cast<bool>(IsImagesEqual(image(), ref.image()));
645}
646
647// Composite two images
648void Magick::Image::composite ( const Image &compositeImage_,
cristyd99b0962010-05-29 23:14:26 +0000649 const ssize_t xOffset_,
650 const ssize_t yOffset_,
cristy3ed852e2009-09-05 21:47:34 +0000651 const CompositeOperator compose_ )
652{
653 // Image supplied as compositeImage is composited with current image and
654 // results in updating current image.
655 modifyImage();
656
657 CompositeImage( image(),
658 compose_,
659 compositeImage_.constImage(),
660 xOffset_,
661 yOffset_ );
662 throwImageException();
663}
664void Magick::Image::composite ( const Image &compositeImage_,
665 const Geometry &offset_,
666 const CompositeOperator compose_ )
667{
668 modifyImage();
669
cristybb503372010-05-27 20:51:26 +0000670 ssize_t x = offset_.xOff();
671 ssize_t y = offset_.yOff();
672 size_t width = columns();
673 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +0000674
675 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
676 &x, &y,
677 &width, &height );
678
679 CompositeImage( image(),
680 compose_,
681 compositeImage_.constImage(),
682 x, y );
683 throwImageException();
684}
685void Magick::Image::composite ( const Image &compositeImage_,
686 const GravityType gravity_,
687 const CompositeOperator compose_ )
688{
689 modifyImage();
690
691 RectangleInfo geometry;
692
693 SetGeometry(compositeImage_.constImage(), &geometry);
694 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
695
696 CompositeImage( image(),
697 compose_,
698 compositeImage_.constImage(),
699 geometry.x, geometry.y );
700 throwImageException();
701}
702
703// Contrast image
cristyeaedf062010-05-29 22:36:02 +0000704void Magick::Image::contrast ( const size_t sharpen_ )
cristy3ed852e2009-09-05 21:47:34 +0000705{
706 modifyImage();
707 ContrastImage ( image(), (MagickBooleanType) sharpen_ );
708 throwImageException();
709}
710
711// Convolve image. Applies a general image convolution kernel to the image.
712// order_ represents the number of columns and rows in the filter kernel.
713// kernel_ is an array of doubles representing the convolution kernel.
cristyeaedf062010-05-29 22:36:02 +0000714void Magick::Image::convolve ( const size_t order_,
cristy3ed852e2009-09-05 21:47:34 +0000715 const double *kernel_ )
716{
717 ExceptionInfo exceptionInfo;
718 GetExceptionInfo( &exceptionInfo );
719 MagickCore::Image* newImage =
720 ConvolveImage ( image(), order_,
721 kernel_, &exceptionInfo );
722 replaceImage( newImage );
723 throwException( exceptionInfo );
724 (void) DestroyExceptionInfo( &exceptionInfo );
725}
726
727// Crop image
728void Magick::Image::crop ( const Geometry &geometry_ )
729{
730 RectangleInfo cropInfo = geometry_;
731 ExceptionInfo exceptionInfo;
732 GetExceptionInfo( &exceptionInfo );
733 MagickCore::Image* newImage =
734 CropImage( image(),
735 &cropInfo,
736 &exceptionInfo);
737 replaceImage( newImage );
738 throwException( exceptionInfo );
739 (void) DestroyExceptionInfo( &exceptionInfo );
740}
741
742// Cycle Color Map
cristyd99b0962010-05-29 23:14:26 +0000743void Magick::Image::cycleColormap ( const ssize_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +0000744{
745 modifyImage();
746 CycleColormapImage( image(), amount_ );
747 throwImageException();
748}
749
750// Despeckle
751void Magick::Image::despeckle ( void )
752{
753 ExceptionInfo exceptionInfo;
754 GetExceptionInfo( &exceptionInfo );
755 MagickCore::Image* newImage =
756 DespeckleImage( image(), &exceptionInfo );
757 replaceImage( newImage );
758 throwException( exceptionInfo );
759 (void) DestroyExceptionInfo( &exceptionInfo );
760}
761
762// Display image
763void Magick::Image::display( void )
764{
765 DisplayImages( imageInfo(), image() );
766}
767
768// Distort image. distorts an image using various distortion methods, by
769// mapping color lookups of the source image to a new destination image
770// usally of the same size as the source image, unless 'bestfit' is set to
771// true.
cristyb32b90a2009-09-07 21:45:48 +0000772void Magick::Image::distort ( const DistortImageMethod method_,
cristybb503372010-05-27 20:51:26 +0000773 const size_t number_arguments_,
cristyb32b90a2009-09-07 21:45:48 +0000774 const double *arguments_,
775 const bool bestfit_ )
cristy3ed852e2009-09-05 21:47:34 +0000776{
777 ExceptionInfo exceptionInfo;
778 GetExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +0000779 MagickCore::Image* newImage = DistortImage ( image(), method_,
780 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
781 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000782 replaceImage( newImage );
783 throwException( exceptionInfo );
784 (void) DestroyExceptionInfo( &exceptionInfo );
785}
786
787// Draw on image using single drawable
788void Magick::Image::draw ( const Magick::Drawable &drawable_ )
789{
790 modifyImage();
791
792 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
793
794 if(wand)
795 {
796 drawable_.operator()(wand);
797
798 if( constImage()->exception.severity == UndefinedException)
799 DrawRender(wand);
800
801 wand=DestroyDrawingWand(wand);
802 }
803
804 throwImageException();
805}
806
807// Draw on image using a drawable list
808void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
809{
810 modifyImage();
811
812 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
813
814 if(wand)
815 {
816 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
817 p != drawable_.end(); p++ )
818 {
819 p->operator()(wand);
820 if( constImage()->exception.severity != UndefinedException)
821 break;
822 }
823
824 if( constImage()->exception.severity == UndefinedException)
825 DrawRender(wand);
826
827 wand=DestroyDrawingWand(wand);
828 }
829
830 throwImageException();
831}
832
833// Hilight edges in image
834void Magick::Image::edge ( const double radius_ )
835{
836 ExceptionInfo exceptionInfo;
837 GetExceptionInfo( &exceptionInfo );
838 MagickCore::Image* newImage =
839 EdgeImage( image(), radius_, &exceptionInfo );
840 replaceImage( newImage );
841 throwException( exceptionInfo );
842 (void) DestroyExceptionInfo( &exceptionInfo );
843}
844
845// Emboss image (hilight edges)
846void Magick::Image::emboss ( const double radius_, const double sigma_ )
847{
848 ExceptionInfo exceptionInfo;
849 GetExceptionInfo( &exceptionInfo );
850 MagickCore::Image* newImage =
851 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
852 replaceImage( newImage );
853 throwException( exceptionInfo );
854 (void) DestroyExceptionInfo( &exceptionInfo );
855}
856
857// Enhance image (minimize noise)
858void Magick::Image::enhance ( void )
859{
860 ExceptionInfo exceptionInfo;
861 GetExceptionInfo( &exceptionInfo );
862 MagickCore::Image* newImage =
863 EnhanceImage( image(), &exceptionInfo );
864 replaceImage( newImage );
865 throwException( exceptionInfo );
866 (void) DestroyExceptionInfo( &exceptionInfo );
867}
868
869// Equalize image (histogram equalization)
870void Magick::Image::equalize ( void )
871{
872 modifyImage();
873 EqualizeImage( image() );
874 throwImageException();
875}
876
877// Erase image to current "background color"
878void Magick::Image::erase ( void )
879{
880 modifyImage();
881 SetImageBackgroundColor( image() );
882 throwImageException();
883}
884
885// Extends image as defined by the geometry.
886//
887void Magick::Image::extent ( const Geometry &geometry_ )
888{
889 RectangleInfo extentInfo = geometry_;
890 modifyImage();
cristy8bf9e292010-02-21 17:48:01 +0000891 ExceptionInfo exceptionInfo;
892 GetExceptionInfo( &exceptionInfo );
cristy1ee42c42010-05-12 12:52:50 +0000893 MagickCore::Image* newImage =
894 ExtentImage ( image(), &extentInfo, &exceptionInfo );
895 replaceImage( newImage );
cristy8bf9e292010-02-21 17:48:01 +0000896 throwException( exceptionInfo );
897 (void) DestroyExceptionInfo( &exceptionInfo );
898}
899void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
900{
901 backgroundColor ( backgroundColor_ );
902 extent ( geometry_ );
903}
cristyff024b42010-02-21 22:55:09 +0000904void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
cristy8bf9e292010-02-21 17:48:01 +0000905{
906 image()->gravity = gravity_;
907 extent ( geometry_ );
908}
909void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
910{
911 image()->gravity = gravity_;
912 backgroundColor ( backgroundColor_ );
913 extent ( geometry_ );
cristy3ed852e2009-09-05 21:47:34 +0000914}
915
916// Flip image (reflect each scanline in the vertical direction)
917void Magick::Image::flip ( void )
918{
919 ExceptionInfo exceptionInfo;
920 GetExceptionInfo( &exceptionInfo );
921 MagickCore::Image* newImage =
922 FlipImage( image(), &exceptionInfo );
923 replaceImage( newImage );
924 throwException( exceptionInfo );
925 (void) DestroyExceptionInfo( &exceptionInfo );
926}
927
928// Flood-fill color across pixels that match the color of the
929// target pixel and are neighbors of the target pixel.
930// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000931void Magick::Image::floodFillColor( const ssize_t x_,
932 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000933 const Magick::Color &fillColor_ )
934{
935 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
936}
937void Magick::Image::floodFillColor( const Geometry &point_,
938 const Magick::Color &fillColor_ )
939{
940 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
941}
942
943// Flood-fill color across pixels starting at target-pixel and
944// stopping at pixels matching specified border color.
945// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000946void Magick::Image::floodFillColor( const ssize_t x_,
947 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000948 const Magick::Color &fillColor_,
949 const Magick::Color &borderColor_ )
950{
951 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
952 borderColor_ );
953}
954void Magick::Image::floodFillColor( const Geometry &point_,
955 const Magick::Color &fillColor_,
956 const Magick::Color &borderColor_ )
957{
958 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
959 borderColor_ );
960}
961
962// Floodfill pixels matching color (within fuzz factor) of target
cristy4c08aed2011-07-01 19:47:50 +0000963// pixel(x,y) with replacement alpha value using method.
cristy35ef8242010-06-03 16:24:13 +0000964void Magick::Image::floodFillOpacity( const ssize_t x_,
965 const ssize_t y_,
cristy4c08aed2011-07-01 19:47:50 +0000966 const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000967 const PaintMethod method_ )
968{
969 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +0000970 PixelInfo target;
971 GetPixelInfo(image(),&target);
cristy3ed852e2009-09-05 21:47:34 +0000972 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
973 target.red=pixel.red;
974 target.green=pixel.green;
975 target.blue=pixel.blue;
cristy4c08aed2011-07-01 19:47:50 +0000976 target.alpha=alpha_;
cristy3ed852e2009-09-05 21:47:34 +0000977 FloodfillPaintImage ( image(),
978 DefaultChannels,
979 options()->drawInfo(), // const DrawInfo *draw_info
980 &target,
cristybb503372010-05-27 20:51:26 +0000981 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +0000982 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
983 throwImageException();
984}
985
986// Flood-fill texture across pixels that match the color of the
987// target pixel and are neighbors of the target pixel.
988// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000989void Magick::Image::floodFillTexture( const ssize_t x_,
990 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000991 const Magick::Image &texture_ )
992{
993 modifyImage();
994
995 // Set drawing pattern
996 options()->fillPattern(texture_.constImage());
997
998 // Get pixel view
999 Pixels pixels(*this);
1000 // Fill image
cristy4c08aed2011-07-01 19:47:50 +00001001 Quantum *p = pixels.get(x_, y_, 1, 1 );
1002 PixelInfo target;
1003 GetPixelInfo(constImage(),&target);
1004 target.red=GetPixelRed(constImage(),p);
1005 target.green=GetPixelGreen(constImage(),p);
1006 target.blue=GetPixelBlue(constImage(),p);
cristy3ed852e2009-09-05 21:47:34 +00001007 if (p)
1008 FloodfillPaintImage ( image(), // Image *image
1009 DefaultChannels,
1010 options()->drawInfo(), // const DrawInfo *draw_info
1011 &target, // const MagickPacket target
cristybb503372010-05-27 20:51:26 +00001012 static_cast<ssize_t>(x_), // const ssize_t x_offset
1013 static_cast<ssize_t>(y_), // const ssize_t y_offset
cristy3ed852e2009-09-05 21:47:34 +00001014 MagickFalse // const PaintMethod method
1015 );
1016
1017 throwImageException();
1018}
1019void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1020 const Magick::Image &texture_ )
1021{
1022 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1023}
1024
1025// Flood-fill texture across pixels starting at target-pixel and
1026// stopping at pixels matching specified border color.
1027// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +00001028void Magick::Image::floodFillTexture( const ssize_t x_,
1029 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001030 const Magick::Image &texture_,
1031 const Magick::Color &borderColor_ )
1032{
1033 modifyImage();
1034
1035 // Set drawing fill pattern
1036 options()->fillPattern(texture_.constImage());
1037
cristy4c08aed2011-07-01 19:47:50 +00001038 PixelInfo target;
1039 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001040 target.red=static_cast<PixelPacket>(borderColor_).red;
1041 target.green=static_cast<PixelPacket>(borderColor_).green;
1042 target.blue=static_cast<PixelPacket>(borderColor_).blue;
1043 FloodfillPaintImage ( image(),
1044 DefaultChannels,
1045 options()->drawInfo(),
1046 &target,
cristybb503372010-05-27 20:51:26 +00001047 static_cast<ssize_t>(x_),
1048 static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +00001049 MagickTrue);
1050
1051 throwImageException();
1052}
1053void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1054 const Magick::Image &texture_,
1055 const Magick::Color &borderColor_ )
1056{
1057 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1058}
1059
1060// Flop image (reflect each scanline in the horizontal direction)
1061void Magick::Image::flop ( void )
1062{
1063 ExceptionInfo exceptionInfo;
1064 GetExceptionInfo( &exceptionInfo );
1065 MagickCore::Image* newImage =
1066 FlopImage( image(), &exceptionInfo );
1067 replaceImage( newImage );
1068 throwException( exceptionInfo );
1069 (void) DestroyExceptionInfo( &exceptionInfo );
1070}
1071
1072// Frame image
1073void Magick::Image::frame ( const Geometry &geometry_ )
1074{
1075 FrameInfo info;
1076
cristybb503372010-05-27 20:51:26 +00001077 info.x = static_cast<ssize_t>(geometry_.width());
1078 info.y = static_cast<ssize_t>(geometry_.height());
1079 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1080 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
cristy3ed852e2009-09-05 21:47:34 +00001081 info.outer_bevel = geometry_.xOff();
1082 info.inner_bevel = geometry_.yOff();
1083
1084 ExceptionInfo exceptionInfo;
1085 GetExceptionInfo( &exceptionInfo );
1086 MagickCore::Image* newImage =
1087 FrameImage( image(), &info, &exceptionInfo );
1088 replaceImage( newImage );
1089 throwException( exceptionInfo );
1090 (void) DestroyExceptionInfo( &exceptionInfo );
1091}
cristyeaedf062010-05-29 22:36:02 +00001092void Magick::Image::frame ( const size_t width_,
1093 const size_t height_,
cristyd99b0962010-05-29 23:14:26 +00001094 const ssize_t outerBevel_, const ssize_t innerBevel_ )
cristy3ed852e2009-09-05 21:47:34 +00001095{
1096 FrameInfo info;
cristybb503372010-05-27 20:51:26 +00001097 info.x = static_cast<ssize_t>(width_);
1098 info.y = static_cast<ssize_t>(height_);
1099 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1100 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1101 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1102 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
cristy3ed852e2009-09-05 21:47:34 +00001103
1104 ExceptionInfo exceptionInfo;
1105 GetExceptionInfo( &exceptionInfo );
1106 MagickCore::Image* newImage =
1107 FrameImage( image(), &info, &exceptionInfo );
1108 replaceImage( newImage );
1109 throwException( exceptionInfo );
1110 (void) DestroyExceptionInfo( &exceptionInfo );
1111}
1112
cristyc9550792009-11-13 20:05:42 +00001113// Fx image. Applies a mathematical expression to the image.
1114void Magick::Image::fx ( const std::string expression )
1115{
1116 ExceptionInfo exceptionInfo;
1117 GetExceptionInfo( &exceptionInfo );
1118 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001119 FxImage ( image(), expression.c_str(), &exceptionInfo );
cristyc9550792009-11-13 20:05:42 +00001120 replaceImage( newImage );
1121 throwException( exceptionInfo );
1122 (void) DestroyExceptionInfo( &exceptionInfo );
1123}
cristy3ed852e2009-09-05 21:47:34 +00001124void Magick::Image::fx ( const std::string expression,
1125 const Magick::ChannelType channel )
1126{
1127 ExceptionInfo exceptionInfo;
1128 GetExceptionInfo( &exceptionInfo );
cristy490408a2011-07-07 14:42:05 +00001129 PushPixelComponentMap( image(), channel );
cristy3ed852e2009-09-05 21:47:34 +00001130 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001131 FxImage ( image(), expression.c_str(), &exceptionInfo );
1132 PopPixelComponentMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001133 replaceImage( newImage );
1134 throwException( exceptionInfo );
1135 (void) DestroyExceptionInfo( &exceptionInfo );
1136}
1137
1138// Gamma correct image
1139void Magick::Image::gamma ( const double gamma_ )
1140{
cristy3ed852e2009-09-05 21:47:34 +00001141 modifyImage();
cristy50fbc382011-07-07 02:19:17 +00001142 GammaImage ( image(), gamma_ );
cristy3ed852e2009-09-05 21:47:34 +00001143}
1144
1145void Magick::Image::gamma ( const double gammaRed_,
1146 const double gammaGreen_,
1147 const double gammaBlue_ )
1148{
1149 char gamma[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001150 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
cristy3ed852e2009-09-05 21:47:34 +00001151 gammaRed_, gammaGreen_, gammaBlue_);
1152
1153 modifyImage();
cristy50fbc382011-07-07 02:19:17 +00001154 GammaImage ( image(), atof(gamma) );
cristy3ed852e2009-09-05 21:47:34 +00001155 throwImageException();
1156}
1157
1158// Gaussian blur image
1159// The number of neighbor pixels to be included in the convolution
1160// mask is specified by 'width_'. The standard deviation of the
1161// gaussian bell curve is specified by 'sigma_'.
1162void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1163{
1164 ExceptionInfo exceptionInfo;
1165 GetExceptionInfo( &exceptionInfo );
1166 MagickCore::Image* newImage =
1167 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1168 replaceImage( newImage );
1169 throwException( exceptionInfo );
1170 (void) DestroyExceptionInfo( &exceptionInfo );
1171}
1172
1173void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1174 const double width_,
1175 const double sigma_ )
1176{
1177 ExceptionInfo exceptionInfo;
1178 GetExceptionInfo( &exceptionInfo );
1179 MagickCore::Image* newImage =
1180 GaussianBlurImageChannel( image(), channel_, width_, sigma_, &exceptionInfo );
1181 replaceImage( newImage );
1182 throwException( exceptionInfo );
1183 (void) DestroyExceptionInfo( &exceptionInfo );
1184}
1185
cristyb32b90a2009-09-07 21:45:48 +00001186// Apply a color lookup table (Hald CLUT) to the image.
1187void Magick::Image::haldClut ( const Image &clutImage_ )
1188{
1189 modifyImage();
1190 (void) HaldClutImage( image(), clutImage_.constImage() );
1191 throwImageException();
1192}
1193
cristy3ed852e2009-09-05 21:47:34 +00001194// Implode image
1195void Magick::Image::implode ( const double factor_ )
1196{
1197 ExceptionInfo exceptionInfo;
1198 GetExceptionInfo( &exceptionInfo );
1199 MagickCore::Image* newImage =
1200 ImplodeImage( image(), factor_, &exceptionInfo );
1201 replaceImage( newImage );
1202 throwException( exceptionInfo );
1203 (void) DestroyExceptionInfo( &exceptionInfo );
1204}
1205
cristy529fcc22009-11-14 18:15:08 +00001206// implements the inverse discrete Fourier transform (IFT) of the image either
1207// as a magnitude / phase or real / imaginary image pair.
1208void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1209{
1210 ExceptionInfo exceptionInfo;
1211 GetExceptionInfo( &exceptionInfo );
1212 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1213 phase_.constImage(), MagickTrue, &exceptionInfo);
1214 replaceImage( newImage );
1215 throwException( exceptionInfo );
1216 (void) DestroyExceptionInfo( &exceptionInfo );
1217}
1218void Magick::Image::inverseFourierTransform ( const Image &phase_,
1219 const bool magnitude_ )
1220{
1221 ExceptionInfo exceptionInfo;
1222 GetExceptionInfo( &exceptionInfo );
1223 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1224 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1225 &exceptionInfo);
1226 replaceImage( newImage );
1227 throwException( exceptionInfo );
1228 (void) DestroyExceptionInfo( &exceptionInfo );
1229}
1230
cristy3ed852e2009-09-05 21:47:34 +00001231// Level image. Adjust the levels of the image by scaling the colors
1232// falling between specified white and black points to the full
1233// available quantum range. The parameters provided represent the
1234// black, mid (gamma), and white points. The black point specifies
1235// the darkest color in the image. Colors darker than the black point
1236// are set to zero. Mid point (gamma) specifies a gamma correction to
1237// apply to the image. White point specifies the lightest color in the
1238// image. Colors brighter than the white point are set to the maximum
1239// quantum value. The black and white point have the valid range 0 to
1240// QuantumRange while gamma has a useful range of 0 to ten.
1241void Magick::Image::level ( const double black_point,
1242 const double white_point,
1243 const double gamma )
1244{
1245 modifyImage();
cristyf89cb1d2011-07-07 01:24:37 +00001246 (void) LevelImage( image(), black_point, white_point, gamma );
cristy3ed852e2009-09-05 21:47:34 +00001247 throwImageException();
1248}
1249
1250// Magnify image by integral size
1251void Magick::Image::magnify ( void )
1252{
1253 ExceptionInfo exceptionInfo;
1254 GetExceptionInfo( &exceptionInfo );
1255 MagickCore::Image* newImage =
1256 MagnifyImage( image(), &exceptionInfo );
1257 replaceImage( newImage );
1258 throwException( exceptionInfo );
1259 (void) DestroyExceptionInfo( &exceptionInfo );
1260}
1261
1262// Remap image colors with closest color from reference image
1263void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1264{
1265 modifyImage();
1266 options()->quantizeDither( dither_ );
1267 RemapImage ( options()->quantizeInfo(), image(),
1268 mapImage_.constImage());
1269 throwImageException();
1270}
cristy4c08aed2011-07-01 19:47:50 +00001271// Floodfill designated area with replacement alpha value
cristy3ed852e2009-09-05 21:47:34 +00001272void Magick::Image::matteFloodfill ( const Color &target_ ,
cristy4c08aed2011-07-01 19:47:50 +00001273 const unsigned int alpha_,
cristyd99b0962010-05-29 23:14:26 +00001274 const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001275 const Magick::PaintMethod method_ )
1276{
1277 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001278 PixelInfo target;
1279 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001280 target.red=static_cast<PixelPacket>(target_).red;
1281 target.green=static_cast<PixelPacket>(target_).green;
1282 target.blue=static_cast<PixelPacket>(target_).blue;
cristy4c08aed2011-07-01 19:47:50 +00001283 target.alpha=alpha_;
cristy3ed852e2009-09-05 21:47:34 +00001284 FloodfillPaintImage ( image(), OpacityChannel, options()->drawInfo(), &target,
1285 x_, y_, method_ == FloodfillMethod ? MagickFalse : MagickTrue);
1286 throwImageException();
1287}
1288
1289// Filter image by replacing each pixel component with the median
1290// color in a circular neighborhood
1291void Magick::Image::medianFilter ( const double radius_ )
1292{
1293 ExceptionInfo exceptionInfo;
1294 GetExceptionInfo( &exceptionInfo );
1295 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001296 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1297 radius_,&exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001298 replaceImage( newImage );
1299 throwException( exceptionInfo );
1300 (void) DestroyExceptionInfo( &exceptionInfo );
1301}
1302
1303// Reduce image by integral size
1304void Magick::Image::minify ( void )
1305{
1306 ExceptionInfo exceptionInfo;
1307 GetExceptionInfo( &exceptionInfo );
1308 MagickCore::Image* newImage =
1309 MinifyImage( image(), &exceptionInfo );
1310 replaceImage( newImage );
1311 throwException( exceptionInfo );
1312 (void) DestroyExceptionInfo( &exceptionInfo );
1313}
1314
1315// Modulate percent hue, saturation, and brightness of an image
1316void Magick::Image::modulate ( const double brightness_,
1317 const double saturation_,
1318 const double hue_ )
1319{
1320 char modulate[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001321 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
cristy3ed852e2009-09-05 21:47:34 +00001322 brightness_, saturation_, hue_);
1323
1324 modifyImage();
1325 ModulateImage( image(), modulate );
1326 throwImageException();
1327}
1328
1329// Motion blur image with specified blur factor
1330// The radius_ parameter specifies the radius of the Gaussian, in
1331// pixels, not counting the center pixel. The sigma_ parameter
1332// specifies the standard deviation of the Laplacian, in pixels.
1333// The angle_ parameter specifies the angle the object appears
1334// to be comming from (zero degrees is from the right).
1335void Magick::Image::motionBlur ( const double radius_,
1336 const double sigma_,
1337 const double angle_ )
1338{
1339 ExceptionInfo exceptionInfo;
1340 GetExceptionInfo( &exceptionInfo );
1341 MagickCore::Image* newImage =
1342 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1343 replaceImage( newImage );
1344 throwException( exceptionInfo );
1345 (void) DestroyExceptionInfo( &exceptionInfo );
1346}
1347
1348// Negate image. Set grayscale_ to true to effect grayscale values
1349// only
1350void Magick::Image::negate ( const bool grayscale_ )
1351{
1352 modifyImage();
1353 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse );
1354 throwImageException();
1355}
1356
1357// Normalize image
1358void Magick::Image::normalize ( void )
1359{
1360 modifyImage();
1361 NormalizeImage ( image() );
1362 throwImageException();
1363}
1364
1365// Oilpaint image
1366void Magick::Image::oilPaint ( const double radius_ )
1367{
1368 ExceptionInfo exceptionInfo;
1369 GetExceptionInfo( &exceptionInfo );
1370 MagickCore::Image* newImage =
1371 OilPaintImage( image(), radius_, &exceptionInfo );
1372 replaceImage( newImage );
1373 throwException( exceptionInfo );
1374 (void) DestroyExceptionInfo( &exceptionInfo );
1375}
1376
cristy4c08aed2011-07-01 19:47:50 +00001377// Set or attenuate the alpha channel. If the image pixels are
1378// opaque then they are set to the specified alpha value, otherwise
1379// they are blended with the supplied alpha value. The value of
1380// alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1381// OpaqueAlpha and TransparentAlpha are available to specify
cristy3ed852e2009-09-05 21:47:34 +00001382// completely opaque or completely transparent, respectively.
cristy4c08aed2011-07-01 19:47:50 +00001383void Magick::Image::alpha ( const unsigned int alpha_ )
cristy3ed852e2009-09-05 21:47:34 +00001384{
1385 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001386 SetImageOpacity( image(), alpha_ );
cristy3ed852e2009-09-05 21:47:34 +00001387}
1388
1389// Change the color of an opaque pixel to the pen color.
1390void Magick::Image::opaque ( const Color &opaqueColor_,
1391 const Color &penColor_ )
1392{
1393 if ( !opaqueColor_.isValid() )
1394 {
1395 throwExceptionExplicit( OptionError,
1396 "Opaque color argument is invalid" );
1397 }
1398 if ( !penColor_.isValid() )
1399 {
1400 throwExceptionExplicit( OptionError,
1401 "Pen color argument is invalid" );
1402 }
1403
1404 modifyImage();
1405 std::string opaqueColor = opaqueColor_;
1406 std::string penColor = penColor_;
1407
cristy4c08aed2011-07-01 19:47:50 +00001408 PixelInfo opaque;
1409 PixelInfo pen;
cristy3ed852e2009-09-05 21:47:34 +00001410 (void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque,&image()->exception);
1411 (void) QueryMagickColor(std::string(penColor_).c_str(),&pen,&image()->exception);
1412 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse );
1413 throwImageException();
1414}
1415
1416// Ping is similar to read except only enough of the image is read to
1417// determine the image columns, rows, and filesize. Access the
1418// columns(), rows(), and fileSize() attributes after invoking ping.
1419// The image data is not valid after calling ping.
1420void Magick::Image::ping ( const std::string &imageSpec_ )
1421{
1422 options()->fileName( imageSpec_ );
1423 ExceptionInfo exceptionInfo;
1424 GetExceptionInfo( &exceptionInfo );
1425 MagickCore::Image* image =
1426 PingImage( imageInfo(), &exceptionInfo );
1427 replaceImage( image );
1428 throwException( exceptionInfo );
1429 (void) DestroyExceptionInfo( &exceptionInfo );
1430}
1431
1432// Ping is similar to read except only enough of the image is read
1433// to determine the image columns, rows, and filesize. Access the
1434// columns(), rows(), and fileSize() attributes after invoking
1435// ping. The image data is not valid after calling ping.
1436void Magick::Image::ping ( const Blob& blob_ )
1437{
1438 ExceptionInfo exceptionInfo;
1439 GetExceptionInfo( &exceptionInfo );
1440 MagickCore::Image* image =
1441 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1442 replaceImage( image );
1443 throwException( exceptionInfo );
1444 (void) DestroyExceptionInfo( &exceptionInfo );
1445}
1446
1447// Execute a named process module using an argc/argv syntax similar to
1448// that accepted by a C 'main' routine. An exception is thrown if the
1449// requested process module doesn't exist, fails to load, or fails during
1450// execution.
cristyd99b0962010-05-29 23:14:26 +00001451void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
cristy3ed852e2009-09-05 21:47:34 +00001452{
1453 modifyImage();
1454
cristyeaedf062010-05-29 22:36:02 +00001455 size_t status =
cristy3ed852e2009-09-05 21:47:34 +00001456 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1457 &image()->exception );
1458
1459 if (status == false)
1460 throwException( image()->exception );
1461}
1462
1463// Quantize colors in image using current quantization settings
1464// Set measureError_ to true in order to measure quantization error
1465void Magick::Image::quantize ( const bool measureError_ )
1466{
1467 modifyImage();
1468
1469 if (measureError_)
1470 options()->quantizeInfo()->measure_error=MagickTrue;
1471 else
1472 options()->quantizeInfo()->measure_error=MagickFalse;
1473
1474 QuantizeImage( options()->quantizeInfo(), image() );
1475
1476 throwImageException();
1477}
1478
1479// Apply an arithmetic or bitwise operator to the image pixel quantums.
1480void Magick::Image::quantumOperator ( const ChannelType channel_,
1481 const MagickEvaluateOperator operator_,
1482 double rvalue_)
1483{
1484 ExceptionInfo exceptionInfo;
1485 GetExceptionInfo( &exceptionInfo );
1486 EvaluateImageChannel( image(), channel_, operator_, rvalue_, &exceptionInfo);
1487 throwException( exceptionInfo );
1488 (void) DestroyExceptionInfo( &exceptionInfo );
1489}
1490
cristyd99b0962010-05-29 23:14:26 +00001491void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00001492 const size_t columns_,
1493 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00001494 const ChannelType channel_,
1495 const MagickEvaluateOperator operator_,
1496 const double rvalue_)
1497{
1498 ExceptionInfo exceptionInfo;
1499 GetExceptionInfo( &exceptionInfo );
1500 RectangleInfo geometry;
1501 geometry.width = columns_;
1502 geometry.height = rows_;
1503 geometry.x = x_;
1504 geometry.y = y_;
1505 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1506 &exceptionInfo );
1507 EvaluateImageChannel( crop_image, channel_, operator_, rvalue_,
1508 &exceptionInfo );
1509 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1510 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1511 crop_image = DestroyImageList(crop_image);
1512 throwException( exceptionInfo );
1513 (void) DestroyExceptionInfo( &exceptionInfo );
1514}
1515
1516// Raise image (lighten or darken the edges of an image to give a 3-D
1517// raised or lowered effect)
1518void Magick::Image::raise ( const Geometry &geometry_ ,
1519 const bool raisedFlag_ )
1520{
1521 RectangleInfo raiseInfo = geometry_;
1522 modifyImage();
1523 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse );
1524 throwImageException();
1525}
1526
1527
1528// Random threshold image.
1529//
1530// Changes the value of individual pixels based on the intensity
1531// of each pixel compared to a random threshold. The result is a
1532// low-contrast, two color image. The thresholds_ argument is a
1533// geometry containing LOWxHIGH thresholds. If the string
1534// contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1535// 3, or 4 will be performed instead. If a channel_ argument is
1536// specified then only the specified channel is altered. This is
1537// a very fast alternative to 'quantize' based dithering.
1538void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1539{
1540 randomThresholdChannel(thresholds_,DefaultChannels);
1541}
1542void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1543 const ChannelType channel_ )
1544{
1545 ExceptionInfo exceptionInfo;
1546 GetExceptionInfo( &exceptionInfo );
1547 modifyImage();
1548 (void) RandomThresholdImageChannel( image(),
1549 channel_,
1550 static_cast<std::string>(thresholds_).c_str(),
1551 &exceptionInfo );
1552 throwImageException();
1553 (void) DestroyExceptionInfo( &exceptionInfo );
1554}
1555
1556// Read image into current object
1557void Magick::Image::read ( const std::string &imageSpec_ )
1558{
1559 options()->fileName( imageSpec_ );
1560
1561 ExceptionInfo exceptionInfo;
1562 GetExceptionInfo( &exceptionInfo );
1563 MagickCore::Image* image =
1564 ReadImage( imageInfo(), &exceptionInfo );
1565
1566 // Ensure that multiple image frames were not read.
1567 if ( image && image->next )
1568 {
1569 // Destroy any extra image frames
1570 MagickCore::Image* next = image->next;
1571 image->next = 0;
1572 next->previous = 0;
1573 DestroyImageList( next );
1574
1575 }
1576 replaceImage( image );
1577 throwException( exceptionInfo );
1578 if ( image )
1579 throwException( image->exception );
1580 (void) DestroyExceptionInfo( &exceptionInfo );
1581}
1582
1583// Read image of specified size into current object
1584void Magick::Image::read ( const Geometry &size_,
1585 const std::string &imageSpec_ )
1586{
1587 size( size_ );
1588 read( imageSpec_ );
1589}
1590
1591// Read image from in-memory BLOB
1592void Magick::Image::read ( const Blob &blob_ )
1593{
1594 ExceptionInfo exceptionInfo;
1595 GetExceptionInfo( &exceptionInfo );
1596 MagickCore::Image* image =
1597 BlobToImage( imageInfo(),
1598 static_cast<const void *>(blob_.data()),
1599 blob_.length(), &exceptionInfo );
1600 replaceImage( image );
1601 throwException( exceptionInfo );
1602 if ( image )
1603 throwException( image->exception );
1604 (void) DestroyExceptionInfo( &exceptionInfo );
1605}
1606
1607// Read image of specified size from in-memory BLOB
1608void Magick::Image::read ( const Blob &blob_,
1609 const Geometry &size_ )
1610{
1611 // Set image size
1612 size( size_ );
1613 // Read from Blob
1614 read( blob_ );
1615}
1616
1617// Read image of specified size and depth from in-memory BLOB
1618void Magick::Image::read ( const Blob &blob_,
1619 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001620 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00001621{
1622 // Set image size
1623 size( size_ );
1624 // Set image depth
1625 depth( depth_ );
1626 // Read from Blob
1627 read( blob_ );
1628}
1629
1630// Read image of specified size, depth, and format from in-memory BLOB
1631void Magick::Image::read ( const Blob &blob_,
1632 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001633 const size_t depth_,
cristy3ed852e2009-09-05 21:47:34 +00001634 const std::string &magick_ )
1635{
1636 // Set image size
1637 size( size_ );
1638 // Set image depth
1639 depth( depth_ );
1640 // Set image magick
1641 magick( magick_ );
1642 // Set explicit image format
1643 fileName( magick_ + ':');
1644 // Read from Blob
1645 read( blob_ );
1646}
1647
1648// Read image of specified size, and format from in-memory BLOB
1649void Magick::Image::read ( const Blob &blob_,
1650 const Geometry &size_,
1651 const std::string &magick_ )
1652{
1653 // Set image size
1654 size( size_ );
1655 // Set image magick
1656 magick( magick_ );
1657 // Set explicit image format
1658 fileName( magick_ + ':');
1659 // Read from Blob
1660 read( blob_ );
1661}
1662
1663// Read image based on raw pixels in memory (ConstituteImage)
cristyeaedf062010-05-29 22:36:02 +00001664void Magick::Image::read ( const size_t width_,
1665 const size_t height_,
cristy3ed852e2009-09-05 21:47:34 +00001666 const std::string &map_,
1667 const StorageType type_,
1668 const void *pixels_ )
1669{
1670 ExceptionInfo exceptionInfo;
1671 GetExceptionInfo( &exceptionInfo );
1672 MagickCore::Image* image =
1673 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1674 &exceptionInfo );
1675 replaceImage( image );
1676 throwException( exceptionInfo );
1677 if ( image )
1678 throwException( image->exception );
1679 (void) DestroyExceptionInfo( &exceptionInfo );
1680}
1681
cristy3ed852e2009-09-05 21:47:34 +00001682// Reduce noise in image
1683void Magick::Image::reduceNoise ( const double order_ )
1684{
1685 ExceptionInfo exceptionInfo;
1686 GetExceptionInfo( &exceptionInfo );
1687 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001688 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1689 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001690 replaceImage( newImage );
1691 throwException( exceptionInfo );
1692 (void) DestroyExceptionInfo( &exceptionInfo );
1693}
1694
1695// Resize image
1696void Magick::Image::resize( const Geometry &geometry_ )
1697{
1698 // Calculate new size. This code should be supported using binary arguments
1699 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00001700 ssize_t x = 0;
1701 ssize_t y = 0;
1702 size_t width = columns();
1703 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001704
1705 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1706 &x, &y,
1707 &width, &height );
1708
1709 ExceptionInfo exceptionInfo;
1710 GetExceptionInfo( &exceptionInfo );
1711 MagickCore::Image* newImage =
1712 ResizeImage( image(),
1713 width,
1714 height,
1715 image()->filter,
1716 1.0,
1717 &exceptionInfo);
1718 replaceImage( newImage );
1719 throwException( exceptionInfo );
1720 (void) DestroyExceptionInfo( &exceptionInfo );
1721}
1722
1723// Roll image
1724void Magick::Image::roll ( const Geometry &roll_ )
1725{
cristybb503372010-05-27 20:51:26 +00001726 ssize_t xOff = roll_.xOff();
cristy3ed852e2009-09-05 21:47:34 +00001727 if ( roll_.xNegative() )
1728 xOff = 0 - xOff;
cristybb503372010-05-27 20:51:26 +00001729 ssize_t yOff = roll_.yOff();
cristy3ed852e2009-09-05 21:47:34 +00001730 if ( roll_.yNegative() )
1731 yOff = 0 - yOff;
1732
1733 ExceptionInfo exceptionInfo;
1734 GetExceptionInfo( &exceptionInfo );
1735 MagickCore::Image* newImage =
1736 RollImage( image(), xOff, yOff, &exceptionInfo );
1737 replaceImage( newImage );
1738 throwException( exceptionInfo );
1739 (void) DestroyExceptionInfo( &exceptionInfo );
1740}
cristyeaedf062010-05-29 22:36:02 +00001741void Magick::Image::roll ( const size_t columns_,
1742 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00001743{
1744 ExceptionInfo exceptionInfo;
1745 GetExceptionInfo( &exceptionInfo );
1746 MagickCore::Image* newImage =
1747 RollImage( image(),
cristybb503372010-05-27 20:51:26 +00001748 static_cast<ssize_t>(columns_),
1749 static_cast<ssize_t>(rows_), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001750 replaceImage( newImage );
1751 throwException( exceptionInfo );
1752 (void) DestroyExceptionInfo( &exceptionInfo );
1753}
1754
1755// Rotate image
1756void Magick::Image::rotate ( const double degrees_ )
1757{
1758 ExceptionInfo exceptionInfo;
1759 GetExceptionInfo( &exceptionInfo );
1760 MagickCore::Image* newImage =
1761 RotateImage( image(), degrees_, &exceptionInfo);
1762 replaceImage( newImage );
1763 throwException( exceptionInfo );
1764 (void) DestroyExceptionInfo( &exceptionInfo );
1765}
1766
1767// Sample image
1768void Magick::Image::sample ( const Geometry &geometry_ )
1769{
cristybb503372010-05-27 20:51:26 +00001770 ssize_t x = 0;
1771 ssize_t y = 0;
1772 size_t width = columns();
1773 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001774
1775 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1776 &x, &y,
1777 &width, &height );
1778
1779 ExceptionInfo exceptionInfo;
1780 GetExceptionInfo( &exceptionInfo );
1781 MagickCore::Image* newImage =
1782 SampleImage( image(), width, height, &exceptionInfo );
1783 replaceImage( newImage );
1784 throwException( exceptionInfo );
1785 (void) DestroyExceptionInfo( &exceptionInfo );
1786}
1787
1788// Scale image
1789void Magick::Image::scale ( const Geometry &geometry_ )
1790{
cristybb503372010-05-27 20:51:26 +00001791 ssize_t x = 0;
1792 ssize_t y = 0;
1793 size_t width = columns();
1794 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001795
1796 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1797 &x, &y,
1798 &width, &height );
1799
1800 ExceptionInfo exceptionInfo;
1801 GetExceptionInfo( &exceptionInfo );
1802 MagickCore::Image* newImage =
1803 ScaleImage( image(), width, height, &exceptionInfo );
1804 replaceImage( newImage );
1805 throwException( exceptionInfo );
1806 (void) DestroyExceptionInfo( &exceptionInfo );
1807}
1808
1809// Segment (coalesce similar image components) by analyzing the
1810// histograms of the color components and identifying units that are
1811// homogeneous with the fuzzy c-means technique.
1812void Magick::Image::segment ( const double clusterThreshold_,
1813 const double smoothingThreshold_ )
1814{
1815 modifyImage();
1816 SegmentImage ( image(),
1817 options()->quantizeColorSpace(),
1818 (MagickBooleanType) options()->verbose(),
1819 clusterThreshold_,
1820 smoothingThreshold_ );
1821 throwImageException();
1822 SyncImage( image() );
1823 throwImageException();
1824}
1825
1826// Shade image using distant light source
1827void Magick::Image::shade ( const double azimuth_,
1828 const double elevation_,
1829 const bool colorShading_ )
1830{
1831 ExceptionInfo exceptionInfo;
1832 GetExceptionInfo( &exceptionInfo );
1833 MagickCore::Image* newImage =
1834 ShadeImage( image(),
1835 colorShading_ == true ? MagickTrue : MagickFalse,
1836 azimuth_,
1837 elevation_,
1838 &exceptionInfo);
1839 replaceImage( newImage );
1840 throwException( exceptionInfo );
1841 (void) DestroyExceptionInfo( &exceptionInfo );
1842}
1843
1844// Sharpen pixels in image
1845void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1846{
1847 ExceptionInfo exceptionInfo;
1848 GetExceptionInfo( &exceptionInfo );
1849 MagickCore::Image* newImage =
1850 SharpenImage( image(),
1851 radius_,
1852 sigma_,
1853 &exceptionInfo );
1854 replaceImage( newImage );
1855 throwException( exceptionInfo );
1856 (void) DestroyExceptionInfo( &exceptionInfo );
1857}
1858
1859void Magick::Image::sharpenChannel ( const ChannelType channel_,
1860 const double radius_, const double sigma_ )
1861{
1862 ExceptionInfo exceptionInfo;
1863 GetExceptionInfo( &exceptionInfo );
1864 MagickCore::Image* newImage =
1865 SharpenImageChannel( image(),
1866 channel_,
1867 radius_,
1868 sigma_,
1869 &exceptionInfo );
1870 replaceImage( newImage );
1871 throwException( exceptionInfo );
1872 (void) DestroyExceptionInfo( &exceptionInfo );
1873}
1874
1875// Shave pixels from image edges.
1876void Magick::Image::shave ( const Geometry &geometry_ )
1877{
1878 RectangleInfo shaveInfo = geometry_;
1879 ExceptionInfo exceptionInfo;
1880 GetExceptionInfo( &exceptionInfo );
1881 MagickCore::Image* newImage =
1882 ShaveImage( image(),
1883 &shaveInfo,
1884 &exceptionInfo);
1885 replaceImage( newImage );
1886 throwException( exceptionInfo );
1887 (void) DestroyExceptionInfo( &exceptionInfo );
1888}
1889
1890// Shear image
1891void Magick::Image::shear ( const double xShearAngle_,
1892 const double yShearAngle_ )
1893{
1894 ExceptionInfo exceptionInfo;
1895 GetExceptionInfo( &exceptionInfo );
1896 MagickCore::Image* newImage =
1897 ShearImage( image(),
1898 xShearAngle_,
1899 yShearAngle_,
1900 &exceptionInfo );
1901 replaceImage( newImage );
1902 throwException( exceptionInfo );
1903 (void) DestroyExceptionInfo( &exceptionInfo );
1904}
1905
1906// Contrast image
cristyeaedf062010-05-29 22:36:02 +00001907void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
cristy3ed852e2009-09-05 21:47:34 +00001908{
1909 modifyImage();
cristy9ee60942011-07-06 14:54:38 +00001910 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint );
cristy3ed852e2009-09-05 21:47:34 +00001911 throwImageException();
1912}
1913
1914// Solarize image (similar to effect seen when exposing a photographic
1915// film to light during the development process)
1916void Magick::Image::solarize ( const double factor_ )
1917{
1918 modifyImage();
1919 SolarizeImage ( image(), factor_ );
1920 throwImageException();
1921}
1922
1923// Sparse color image, given a set of coordinates, interpolates the colors
1924// found at those coordinates, across the whole image, using various methods.
1925//
1926void Magick::Image::sparseColor ( const ChannelType channel,
1927 const SparseColorMethod method,
cristybb503372010-05-27 20:51:26 +00001928 const size_t number_arguments,
cristy3ed852e2009-09-05 21:47:34 +00001929 const double *arguments )
1930{
1931 ExceptionInfo exceptionInfo;
1932 GetExceptionInfo( &exceptionInfo );
1933 MagickCore::Image* newImage = SparseColorImage ( image(), channel, method,
1934 number_arguments, arguments, &exceptionInfo );
1935 replaceImage( newImage );
1936 throwException( exceptionInfo );
1937 (void) DestroyExceptionInfo( &exceptionInfo );
1938}
1939
1940// Spread pixels randomly within image by specified ammount
cristyeaedf062010-05-29 22:36:02 +00001941void Magick::Image::spread ( const size_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +00001942{
1943 ExceptionInfo exceptionInfo;
1944 GetExceptionInfo( &exceptionInfo );
1945 MagickCore::Image* newImage =
1946 SpreadImage( image(),
1947 amount_,
1948 &exceptionInfo );
1949 replaceImage( newImage );
1950 throwException( exceptionInfo );
1951 (void) DestroyExceptionInfo( &exceptionInfo );
1952}
1953
1954// Add a digital watermark to the image (based on second image)
1955void Magick::Image::stegano ( const Image &watermark_ )
1956{
1957 ExceptionInfo exceptionInfo;
1958 GetExceptionInfo( &exceptionInfo );
1959 MagickCore::Image* newImage =
1960 SteganoImage( image(),
1961 watermark_.constImage(),
1962 &exceptionInfo);
1963 replaceImage( newImage );
1964 throwException( exceptionInfo );
1965 (void) DestroyExceptionInfo( &exceptionInfo );
1966}
1967
1968// Stereo image (left image is current image)
1969void Magick::Image::stereo ( const Image &rightImage_ )
1970{
1971 ExceptionInfo exceptionInfo;
1972 GetExceptionInfo( &exceptionInfo );
1973 MagickCore::Image* newImage =
1974 StereoImage( image(),
1975 rightImage_.constImage(),
1976 &exceptionInfo);
1977 replaceImage( newImage );
1978 throwException( exceptionInfo );
1979 (void) DestroyExceptionInfo( &exceptionInfo );
1980}
1981
1982// Swirl image
1983void Magick::Image::swirl ( const double degrees_ )
1984{
1985 ExceptionInfo exceptionInfo;
1986 GetExceptionInfo( &exceptionInfo );
1987 MagickCore::Image* newImage =
1988 SwirlImage( image(), degrees_,
1989 &exceptionInfo);
1990 replaceImage( newImage );
1991 throwException( exceptionInfo );
1992 (void) DestroyExceptionInfo( &exceptionInfo );
1993}
1994
1995// Texture image
1996void Magick::Image::texture ( const Image &texture_ )
1997{
1998 modifyImage();
1999 TextureImage( image(), texture_.constImage() );
2000 throwImageException();
2001}
2002
2003// Threshold image
2004void Magick::Image::threshold ( const double threshold_ )
2005{
2006 modifyImage();
2007 BilevelImage( image(), threshold_ );
2008 throwImageException();
2009}
2010
2011// Transform image based on image geometry only
2012void Magick::Image::transform ( const Geometry &imageGeometry_ )
2013{
2014 modifyImage();
2015 TransformImage ( &(image()), 0,
2016 std::string(imageGeometry_).c_str() );
2017 throwImageException();
2018}
2019// Transform image based on image and crop geometries
2020void Magick::Image::transform ( const Geometry &imageGeometry_,
2021 const Geometry &cropGeometry_ )
2022{
2023 modifyImage();
2024 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2025 std::string(imageGeometry_).c_str() );
2026 throwImageException();
2027}
2028
2029// Add matte image to image, setting pixels matching color to transparent
2030void Magick::Image::transparent ( const Color &color_ )
2031{
2032 if ( !color_.isValid() )
2033 {
2034 throwExceptionExplicit( OptionError,
2035 "Color argument is invalid" );
2036 }
2037
2038 std::string color = color_;
2039
cristy4c08aed2011-07-01 19:47:50 +00002040 PixelInfo target;
cristy3ed852e2009-09-05 21:47:34 +00002041 (void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
2042 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00002043 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse );
cristy3ed852e2009-09-05 21:47:34 +00002044 throwImageException();
2045}
2046
2047// Add matte image to image, setting pixels matching color to transparent
2048void Magick::Image::transparentChroma(const Color &colorLow_,
2049 const Color &colorHigh_)
2050{
2051 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2052 {
2053 throwExceptionExplicit( OptionError,
2054 "Color argument is invalid" );
2055 }
2056
2057 std::string colorLow = colorLow_;
2058 std::string colorHigh = colorHigh_;
2059
cristy4c08aed2011-07-01 19:47:50 +00002060 PixelInfo targetLow;
2061 PixelInfo targetHigh;
cristy3ed852e2009-09-05 21:47:34 +00002062 (void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
2063 &image()->exception);
2064 (void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
2065 &image()->exception);
2066 modifyImage();
2067 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
cristy4c08aed2011-07-01 19:47:50 +00002068 TransparentAlpha, MagickFalse );
cristy3ed852e2009-09-05 21:47:34 +00002069 throwImageException();
2070}
2071
2072
2073// Trim edges that are the background color from the image
2074void Magick::Image::trim ( void )
2075{
2076 ExceptionInfo exceptionInfo;
2077 GetExceptionInfo( &exceptionInfo );
2078 MagickCore::Image* newImage =
2079 TrimImage( image(), &exceptionInfo);
2080 replaceImage( newImage );
2081 throwException( exceptionInfo );
2082 (void) DestroyExceptionInfo( &exceptionInfo );
2083}
2084
2085// Replace image with a sharpened version of the original image
2086// using the unsharp mask algorithm.
2087// radius_
2088// the radius of the Gaussian, in pixels, not counting the
2089// center pixel.
2090// sigma_
2091// the standard deviation of the Gaussian, in pixels.
2092// amount_
2093// the percentage of the difference between the original and
2094// the blur image that is added back into the original.
2095// threshold_
2096// the threshold in pixels needed to apply the diffence amount.
2097void Magick::Image::unsharpmask ( const double radius_,
2098 const double sigma_,
2099 const double amount_,
2100 const double threshold_ )
2101{
2102 ExceptionInfo exceptionInfo;
2103 GetExceptionInfo( &exceptionInfo );
2104 MagickCore::Image* newImage =
2105 UnsharpMaskImage( image(),
2106 radius_,
2107 sigma_,
2108 amount_,
2109 threshold_,
2110 &exceptionInfo );
2111 replaceImage( newImage );
2112 throwException( exceptionInfo );
2113 (void) DestroyExceptionInfo( &exceptionInfo );
2114}
2115
2116void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2117 const double radius_,
2118 const double sigma_,
2119 const double amount_,
2120 const double threshold_ )
2121{
2122 ExceptionInfo exceptionInfo;
2123 GetExceptionInfo( &exceptionInfo );
2124 MagickCore::Image* newImage =
2125 UnsharpMaskImageChannel( image(),
2126 channel_,
2127 radius_,
2128 sigma_,
2129 amount_,
2130 threshold_,
2131 &exceptionInfo );
2132 replaceImage( newImage );
2133 throwException( exceptionInfo );
2134 (void) DestroyExceptionInfo( &exceptionInfo );
2135}
2136
2137// Map image pixels to a sine wave
2138void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2139{
2140 ExceptionInfo exceptionInfo;
2141 GetExceptionInfo( &exceptionInfo );
2142 MagickCore::Image* newImage =
2143 WaveImage( image(),
2144 amplitude_,
2145 wavelength_,
2146 &exceptionInfo);
2147 replaceImage( newImage );
2148 throwException( exceptionInfo );
2149 (void) DestroyExceptionInfo( &exceptionInfo );
2150}
2151
2152// Write image to file
2153void Magick::Image::write( const std::string &imageSpec_ )
2154{
2155 modifyImage();
2156 fileName( imageSpec_ );
2157 WriteImage( imageInfo(), image() );
2158 throwImageException();
2159}
2160
2161// Write image to in-memory BLOB
2162void Magick::Image::write ( Blob *blob_ )
2163{
2164 modifyImage();
2165 size_t length = 2048; // Efficient size for small images
2166 ExceptionInfo exceptionInfo;
2167 GetExceptionInfo( &exceptionInfo );
2168 void* data = ImageToBlob( imageInfo(),
2169 image(),
2170 &length,
2171 &exceptionInfo);
2172 throwException( exceptionInfo );
2173 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2174 throwImageException();
2175 (void) DestroyExceptionInfo( &exceptionInfo );
2176}
2177void Magick::Image::write ( Blob *blob_,
2178 const std::string &magick_ )
2179{
2180 modifyImage();
2181 magick(magick_);
2182 size_t length = 2048; // Efficient size for small images
2183 ExceptionInfo exceptionInfo;
2184 GetExceptionInfo( &exceptionInfo );
2185 void* data = ImageToBlob( imageInfo(),
2186 image(),
2187 &length,
2188 &exceptionInfo);
2189 throwException( exceptionInfo );
2190 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2191 throwImageException();
2192 (void) DestroyExceptionInfo( &exceptionInfo );
2193}
2194void Magick::Image::write ( Blob *blob_,
2195 const std::string &magick_,
cristyeaedf062010-05-29 22:36:02 +00002196 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002197{
2198 modifyImage();
2199 magick(magick_);
2200 depth(depth_);
2201 size_t length = 2048; // Efficient size for small images
2202 ExceptionInfo exceptionInfo;
2203 GetExceptionInfo( &exceptionInfo );
2204 void* data = ImageToBlob( imageInfo(),
2205 image(),
2206 &length,
2207 &exceptionInfo);
2208 throwException( exceptionInfo );
2209 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2210 throwImageException();
2211 (void) DestroyExceptionInfo( &exceptionInfo );
2212}
2213
2214// Write image to an array of pixels with storage type specified
2215// by user (ExportImagePixels), e.g.
2216// image.write( 0, 0, 640, 1, "RGB", 0, pixels );
cristyd99b0962010-05-29 23:14:26 +00002217void Magick::Image::write ( const ssize_t x_,
2218 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00002219 const size_t columns_,
2220 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00002221 const std::string &map_,
2222 const StorageType type_,
2223 void *pixels_ )
2224{
2225 ExceptionInfo exceptionInfo;
2226 GetExceptionInfo( &exceptionInfo );
2227 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2228 pixels_,
2229 &exceptionInfo);
2230 throwException( exceptionInfo );
2231 (void) DestroyExceptionInfo( &exceptionInfo );
2232}
2233
2234// Zoom image
2235void Magick::Image::zoom( const Geometry &geometry_ )
2236{
2237 // Calculate new size. This code should be supported using binary arguments
2238 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00002239 ssize_t x = 0;
2240 ssize_t y = 0;
2241 size_t width = columns();
2242 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00002243
2244 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2245 &x, &y,
2246 &width, &height );
2247
2248 ExceptionInfo exceptionInfo;
2249 GetExceptionInfo( &exceptionInfo );
2250 MagickCore::Image* newImage =
cristy391f1ce2010-09-09 17:23:28 +00002251 ResizeImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00002252 width,
2253 height,
cristy391f1ce2010-09-09 17:23:28 +00002254 image()->filter,
2255 image()->blur,
cristy3ed852e2009-09-05 21:47:34 +00002256 &exceptionInfo);
2257 replaceImage( newImage );
2258 throwException( exceptionInfo );
2259 (void) DestroyExceptionInfo( &exceptionInfo );
2260}
2261
2262/*
2263 * Methods for setting image attributes
2264 *
2265 */
2266
2267// Join images into a single multi-image file
2268void Magick::Image::adjoin ( const bool flag_ )
2269{
2270 modifyImage();
2271 options()->adjoin( flag_ );
2272}
2273bool Magick::Image::adjoin ( void ) const
2274{
2275 return constOptions()->adjoin();
2276}
2277
2278// Remove pixel aliasing
2279void Magick::Image::antiAlias( const bool flag_ )
2280{
2281 modifyImage();
cristyeaedf062010-05-29 22:36:02 +00002282 options()->antiAlias( static_cast<size_t>(flag_) );
cristy3ed852e2009-09-05 21:47:34 +00002283}
2284bool Magick::Image::antiAlias( void )
2285{
2286 return static_cast<bool>( options()->antiAlias( ) );
2287}
2288
2289// Animation inter-frame delay
cristyeaedf062010-05-29 22:36:02 +00002290void Magick::Image::animationDelay ( const size_t delay_ )
cristy3ed852e2009-09-05 21:47:34 +00002291{
2292 modifyImage();
2293 image()->delay = delay_;
2294}
cristyeaedf062010-05-29 22:36:02 +00002295size_t Magick::Image::animationDelay ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002296{
2297 return constImage()->delay;
2298}
2299
2300// Number of iterations to play animation
cristyeaedf062010-05-29 22:36:02 +00002301void Magick::Image::animationIterations ( const size_t iterations_ )
cristy3ed852e2009-09-05 21:47:34 +00002302{
2303 modifyImage();
2304 image()->iterations = iterations_;
2305}
cristyeaedf062010-05-29 22:36:02 +00002306size_t Magick::Image::animationIterations ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002307{
2308 return constImage()->iterations;
2309}
2310
2311// Access/Update a named image attribute
2312void Magick::Image::attribute ( const std::string name_,
2313 const std::string value_ )
2314{
2315 modifyImage();
2316 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2317}
2318std::string Magick::Image::attribute ( const std::string name_ )
2319{
2320 const char *value = GetImageProperty( constImage(), name_.c_str() );
2321
2322 if ( value )
2323 return std::string( value );
2324
2325 return std::string(); // Intentionally no exception
2326}
2327
2328// Background color
cristy391f1ce2010-09-09 17:23:28 +00002329void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002330{
2331 modifyImage();
2332
cristy391f1ce2010-09-09 17:23:28 +00002333 if ( backgroundColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002334 {
cristy391f1ce2010-09-09 17:23:28 +00002335 image()->background_color = backgroundColor_;
cristy3ed852e2009-09-05 21:47:34 +00002336 }
2337 else
2338 {
cristy391f1ce2010-09-09 17:23:28 +00002339 image()->background_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002340 }
2341
cristy391f1ce2010-09-09 17:23:28 +00002342 options()->backgroundColor( backgroundColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002343}
2344Magick::Color Magick::Image::backgroundColor ( void ) const
2345{
2346 return constOptions()->backgroundColor( );
2347}
2348
2349// Background fill texture
2350void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2351{
2352 modifyImage();
2353 options()->backgroundTexture( backgroundTexture_ );
2354}
2355std::string Magick::Image::backgroundTexture ( void ) const
2356{
2357 return constOptions()->backgroundTexture( );
2358}
2359
2360// Original image columns
cristyeaedf062010-05-29 22:36:02 +00002361size_t Magick::Image::baseColumns ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002362{
2363 return constImage()->magick_columns;
2364}
2365
2366// Original image name
2367std::string Magick::Image::baseFilename ( void ) const
2368{
2369 return std::string(constImage()->magick_filename);
2370}
2371
2372// Original image rows
cristyeaedf062010-05-29 22:36:02 +00002373size_t Magick::Image::baseRows ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002374{
2375 return constImage()->magick_rows;
2376}
2377
2378// Border color
cristy391f1ce2010-09-09 17:23:28 +00002379void Magick::Image::borderColor ( const Color &borderColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002380{
2381 modifyImage();
2382
cristy391f1ce2010-09-09 17:23:28 +00002383 if ( borderColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002384 {
cristy391f1ce2010-09-09 17:23:28 +00002385 image()->border_color = borderColor_;
cristy3ed852e2009-09-05 21:47:34 +00002386 }
2387 else
2388 {
cristy391f1ce2010-09-09 17:23:28 +00002389 image()->border_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002390 }
2391
cristy391f1ce2010-09-09 17:23:28 +00002392 options()->borderColor( borderColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002393}
2394Magick::Color Magick::Image::borderColor ( void ) const
2395{
2396 return constOptions()->borderColor( );
2397}
2398
2399// Return smallest bounding box enclosing non-border pixels. The
2400// current fuzz value is used when discriminating between pixels.
2401// This is the crop bounding box used by crop(Geometry(0,0));
2402Magick::Geometry Magick::Image::boundingBox ( void ) const
2403{
2404 ExceptionInfo exceptionInfo;
2405 GetExceptionInfo( &exceptionInfo );
2406 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2407 throwException( exceptionInfo );
2408 (void) DestroyExceptionInfo( &exceptionInfo );
2409 return Geometry( bbox );
2410}
2411
2412// Text bounding-box base color
2413void Magick::Image::boxColor ( const Color &boxColor_ )
2414{
2415 modifyImage();
2416 options()->boxColor( boxColor_ );
2417}
2418Magick::Color Magick::Image::boxColor ( void ) const
2419{
2420 return constOptions()->boxColor( );
2421}
2422
2423// Pixel cache threshold. Once this threshold is exceeded, all
2424// subsequent pixels cache operations are to/from disk.
2425// This setting is shared by all Image objects.
2426/* static */
cristyeaedf062010-05-29 22:36:02 +00002427void Magick::Image::cacheThreshold ( const size_t threshold_ )
cristy3ed852e2009-09-05 21:47:34 +00002428{
2429 SetMagickResourceLimit( MemoryResource, threshold_ );
2430}
2431
2432void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2433{
2434 modifyImage();
2435 image()->chromaticity.blue_primary.x = x_;
2436 image()->chromaticity.blue_primary.y = y_;
2437}
2438void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2439{
2440 *x_ = constImage()->chromaticity.blue_primary.x;
2441 *y_ = constImage()->chromaticity.blue_primary.y;
2442}
2443
2444void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2445{
2446 modifyImage();
2447 image()->chromaticity.green_primary.x = x_;
2448 image()->chromaticity.green_primary.y = y_;
2449}
2450void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2451{
2452 *x_ = constImage()->chromaticity.green_primary.x;
2453 *y_ = constImage()->chromaticity.green_primary.y;
2454}
2455
2456void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2457{
2458 modifyImage();
2459 image()->chromaticity.red_primary.x = x_;
2460 image()->chromaticity.red_primary.y = y_;
2461}
2462void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2463{
2464 *x_ = constImage()->chromaticity.red_primary.x;
2465 *y_ = constImage()->chromaticity.red_primary.y;
2466}
2467
2468void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2469{
2470 modifyImage();
2471 image()->chromaticity.white_point.x = x_;
2472 image()->chromaticity.white_point.y = y_;
2473}
2474void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2475{
2476 *x_ = constImage()->chromaticity.white_point.x;
2477 *y_ = constImage()->chromaticity.white_point.y;
2478}
2479
2480// Set image storage class
2481void Magick::Image::classType ( const ClassType class_ )
2482{
2483 if ( classType() == PseudoClass && class_ == DirectClass )
2484 {
2485 // Use SyncImage to synchronize the DirectClass pixels with the
2486 // color map and then set to DirectClass type.
2487 modifyImage();
2488 SyncImage( image() );
2489 image()->colormap = (PixelPacket *)
2490 RelinquishMagickMemory( image()->colormap );
2491 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2492 return;
2493 }
2494
2495 if ( classType() == DirectClass && class_ == PseudoClass )
2496 {
2497 // Quantize to create PseudoClass color map
2498 modifyImage();
cristye6bbc092010-05-12 17:00:47 +00002499 quantizeColors(MaxColormapSize);
cristy3ed852e2009-09-05 21:47:34 +00002500 quantize();
2501 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2502 }
2503}
2504
2505// Associate a clip mask with the image. The clip mask must be the
2506// same dimensions as the image. Pass an invalid image to unset an
2507// existing clip mask.
2508void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2509{
2510 modifyImage();
2511
2512 if( clipMask_.isValid() )
2513 {
2514 // Set clip mask
2515 SetImageClipMask( image(), clipMask_.constImage() );
2516 }
2517 else
2518 {
2519 // Unset existing clip mask
2520 SetImageClipMask( image(), 0 );
2521 }
2522}
2523Magick::Image Magick::Image::clipMask ( void ) const
2524{
2525 ExceptionInfo exceptionInfo;
2526 GetExceptionInfo( &exceptionInfo );
2527 MagickCore::Image* image =
2528 GetImageClipMask( constImage(), &exceptionInfo );
2529 throwException( exceptionInfo );
2530 (void) DestroyExceptionInfo( &exceptionInfo );
2531 return Magick::Image( image );
2532}
2533
2534void Magick::Image::colorFuzz ( const double fuzz_ )
2535{
2536 modifyImage();
2537 image()->fuzz = fuzz_;
2538 options()->colorFuzz( fuzz_ );
2539}
2540double Magick::Image::colorFuzz ( void ) const
2541{
2542 return constOptions()->colorFuzz( );
2543}
2544
2545// Set color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002546void Magick::Image::colorMap ( const size_t index_,
cristy3ed852e2009-09-05 21:47:34 +00002547 const Color &color_ )
2548{
2549 MagickCore::Image* imageptr = image();
2550
2551 if (index_ > (MaxColormapSize-1) )
2552 throwExceptionExplicit( OptionError,
2553 "Colormap index must be less than MaxColormapSize" );
2554
2555 if ( !color_.isValid() )
2556 throwExceptionExplicit( OptionError,
2557 "Color argument is invalid");
2558 modifyImage();
2559
2560 // Ensure that colormap size is large enough
2561 if ( colorMapSize() < (index_+1) )
2562 colorMapSize( index_ + 1 );
2563
2564 // Set color at index in colormap
2565 (imageptr->colormap)[index_] = color_;
2566}
2567// Return color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002568Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
cristy3ed852e2009-09-05 21:47:34 +00002569{
2570 const MagickCore::Image* imageptr = constImage();
2571
2572 if ( !imageptr->colormap )
2573 throwExceptionExplicit( OptionError,
2574 "Image does not contain a colormap");
2575
2576 if ( index_ > imageptr->colors-1 )
2577 throwExceptionExplicit( OptionError,
2578 "Index out of range");
2579
2580 return Magick::Color( (imageptr->colormap)[index_] );
2581}
2582
2583// Colormap size (number of colormap entries)
cristyeaedf062010-05-29 22:36:02 +00002584void Magick::Image::colorMapSize ( const size_t entries_ )
cristy3ed852e2009-09-05 21:47:34 +00002585{
2586 if (entries_ >MaxColormapSize )
2587 throwExceptionExplicit( OptionError,
2588 "Colormap entries must not exceed MaxColormapSize" );
2589
2590 modifyImage();
2591
2592 MagickCore::Image* imageptr = image();
2593
2594 if( !imageptr->colormap )
2595 {
2596 // Allocate colormap
2597 imageptr->colormap =
2598 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2599 imageptr->colors = 0;
2600 }
2601 else if ( entries_ > imageptr->colors )
2602 {
2603 // Re-allocate colormap
2604 imageptr->colormap=(PixelPacket *)
2605 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2606 }
2607
2608 // Initialize any new colormap entries as all black
2609 Color black(0,0,0);
cristyeaedf062010-05-29 22:36:02 +00002610 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
cristy3ed852e2009-09-05 21:47:34 +00002611 (imageptr->colormap)[i] = black;
2612
2613 imageptr->colors = entries_;
2614}
cristyeaedf062010-05-29 22:36:02 +00002615size_t Magick::Image::colorMapSize ( void )
cristy3ed852e2009-09-05 21:47:34 +00002616{
2617 const MagickCore::Image* imageptr = constImage();
2618
2619 if ( !imageptr->colormap )
2620 throwExceptionExplicit( OptionError,
2621 "Image does not contain a colormap");
2622
2623 return imageptr->colors;
2624}
2625
2626// Image colorspace
2627void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2628{
2629 // Nothing to do?
2630 if ( image()->colorspace == colorSpace_ )
2631 return;
2632
2633 modifyImage();
2634
2635 if ( colorSpace_ != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002636 colorSpace_ != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002637 colorSpace_ != TransparentColorspace &&
2638 colorSpace_ != GRAYColorspace )
2639 {
2640 if (image()->colorspace != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002641 image()->colorspace != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002642 image()->colorspace != TransparentColorspace &&
2643 image()->colorspace != GRAYColorspace)
2644 {
2645 /* Transform to RGB colorspace as intermediate step */
2646 TransformRGBImage( image(), image()->colorspace );
2647 throwImageException();
2648 }
2649 /* Transform to final non-RGB colorspace */
2650 RGBTransformImage( image(), colorSpace_ );
2651 throwImageException();
2652 return;
2653 }
2654
2655 if ( colorSpace_ == RGBColorspace ||
cristy510d06a2011-07-06 23:43:54 +00002656 colorSpace_ == sRGBColorspace ||
cristy3ed852e2009-09-05 21:47:34 +00002657 colorSpace_ == TransparentColorspace ||
2658 colorSpace_ == GRAYColorspace )
2659 {
2660 /* Transform to a RGB-type colorspace */
2661 TransformRGBImage( image(), image()->colorspace );
2662 throwImageException();
2663 return;
2664 }
2665}
2666Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2667{
2668 return constImage()->colorspace;
2669}
2670
2671// Set image colorspace type.
2672void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2673{
2674 modifyImage();
2675 options()->colorspaceType( colorSpace_ );
2676}
2677Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2678{
2679 return constOptions()->colorspaceType();
2680}
2681
2682
2683// Comment string
2684void Magick::Image::comment ( const std::string &comment_ )
2685{
2686 modifyImage();
2687 SetImageProperty( image(), "Comment", NULL );
2688 if ( comment_.length() > 0 )
2689 SetImageProperty( image(), "Comment", comment_.c_str() );
2690 throwImageException();
2691}
2692std::string Magick::Image::comment ( void ) const
2693{
2694 const char *value = GetImageProperty( constImage(), "Comment" );
2695
2696 if ( value )
2697 return std::string( value );
2698
2699 return std::string(); // Intentionally no exception
2700}
2701
2702// Composition operator to be used when composition is implicitly used
2703// (such as for image flattening).
2704void Magick::Image::compose (const CompositeOperator compose_)
2705{
2706 image()->compose=compose_;
2707}
2708
2709Magick::CompositeOperator Magick::Image::compose ( void ) const
2710{
2711 return constImage()->compose;
2712}
2713
2714// Compression algorithm
2715void Magick::Image::compressType ( const CompressionType compressType_ )
2716{
2717 modifyImage();
2718 image()->compression = compressType_;
2719 options()->compressType( compressType_ );
2720}
2721Magick::CompressionType Magick::Image::compressType ( void ) const
2722{
2723 return constImage()->compression;
2724}
2725
2726// Enable printing of debug messages from ImageMagick
2727void Magick::Image::debug ( const bool flag_ )
2728{
2729 modifyImage();
2730 options()->debug( flag_ );
2731}
2732bool Magick::Image::debug ( void ) const
2733{
2734 return constOptions()->debug();
2735}
2736
2737// Tagged image format define (set/access coder-specific option) The
2738// magick_ option specifies the coder the define applies to. The key_
2739// option provides the key specific to that coder. The value_ option
2740// provides the value to set (if any). See the defineSet() method if the
2741// key must be removed entirely.
2742void Magick::Image::defineValue ( const std::string &magick_,
2743 const std::string &key_,
2744 const std::string &value_ )
2745{
2746 modifyImage();
2747 std::string format = magick_ + ":" + key_;
2748 std::string option = value_;
2749 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2750}
2751std::string Magick::Image::defineValue ( const std::string &magick_,
2752 const std::string &key_ ) const
2753{
2754 std::string definition = magick_ + ":" + key_;
2755 const char *option =
2756 GetImageOption ( constImageInfo(), definition.c_str() );
2757 if (option)
2758 return std::string( option );
2759 return std::string( );
2760}
2761
2762// Tagged image format define. Similar to the defineValue() method
2763// except that passing the flag_ value 'true' creates a value-less
2764// define with that format and key. Passing the flag_ value 'false'
2765// removes any existing matching definition. The method returns 'true'
2766// if a matching key exists, and 'false' if no matching key exists.
2767void Magick::Image::defineSet ( const std::string &magick_,
2768 const std::string &key_,
2769 bool flag_ )
2770{
2771 modifyImage();
2772 std::string definition = magick_ + ":" + key_;
2773 if (flag_)
2774 {
2775 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2776 }
2777 else
2778 {
2779 DeleteImageOption( imageInfo(), definition.c_str() );
2780 }
2781}
2782bool Magick::Image::defineSet ( const std::string &magick_,
2783 const std::string &key_ ) const
2784{
2785 std::string key = magick_ + ":" + key_;
2786 const char *option =
2787 GetImageOption ( constImageInfo(), key.c_str() );
2788 if (option)
2789 return true;
2790 return false;
2791}
2792
2793// Pixel resolution
2794void Magick::Image::density ( const Geometry &density_ )
2795{
2796 modifyImage();
2797 options()->density( density_ );
2798 if ( density_.isValid() )
2799 {
2800 image()->x_resolution = density_.width();
2801 if ( density_.height() != 0 )
2802 {
2803 image()->y_resolution = density_.height();
2804 }
2805 else
2806 {
2807 image()->y_resolution = density_.width();
2808 }
2809 }
2810 else
2811 {
2812 // Reset to default
2813 image()->x_resolution = 0;
2814 image()->y_resolution = 0;
2815 }
2816}
2817Magick::Geometry Magick::Image::density ( void ) const
2818{
2819 if (isValid())
2820 {
cristy35ef8242010-06-03 16:24:13 +00002821 ssize_t x_resolution=72;
2822 ssize_t y_resolution=72;
cristy3ed852e2009-09-05 21:47:34 +00002823
2824 if (constImage()->x_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002825 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002826
2827 if (constImage()->y_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002828 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002829
2830 return Geometry(x_resolution,y_resolution);
2831 }
2832
2833 return constOptions()->density( );
2834}
2835
2836// Image depth (bits allocated to red/green/blue components)
cristyeaedf062010-05-29 22:36:02 +00002837void Magick::Image::depth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002838{
cristyeaedf062010-05-29 22:36:02 +00002839 size_t depth = depth_;
cristy3ed852e2009-09-05 21:47:34 +00002840
2841 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2842 depth=MAGICKCORE_QUANTUM_DEPTH;
2843
2844 modifyImage();
2845 image()->depth=depth;
2846 options()->depth( depth );
2847}
cristyeaedf062010-05-29 22:36:02 +00002848size_t Magick::Image::depth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002849{
2850 return constImage()->depth;
2851}
2852
2853std::string Magick::Image::directory ( void ) const
2854{
2855 if ( constImage()->directory )
2856 return std::string( constImage()->directory );
2857
2858 throwExceptionExplicit( CorruptImageWarning,
2859 "Image does not contain a directory");
2860
2861 return std::string();
2862}
2863
2864// Endianness (little like Intel or big like SPARC) for image
2865// formats which support endian-specific options.
2866void Magick::Image::endian ( const Magick::EndianType endian_ )
2867{
2868 modifyImage();
2869 options()->endian( endian_ );
2870 image()->endian = endian_;
2871}
2872Magick::EndianType Magick::Image::endian ( void ) const
2873{
2874 return constImage()->endian;
2875}
2876
2877// EXIF profile (BLOB)
2878void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
2879{
2880 modifyImage();
2881 if ( exifProfile_.data() != 0 )
2882 {
2883 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
2884 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
2885 (void) SetImageProfile( image(), "exif", exif_profile);
2886 exif_profile =DestroyStringInfo( exif_profile );
2887 }
2888}
2889Magick::Blob Magick::Image::exifProfile( void ) const
2890{
2891 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
2892 if ( exif_profile == (StringInfo *) NULL)
2893 return Blob( 0, 0 );
2894 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
2895}
2896
2897// Image file name
2898void Magick::Image::fileName ( const std::string &fileName_ )
2899{
2900 modifyImage();
2901
2902 fileName_.copy( image()->filename,
2903 sizeof(image()->filename) - 1 );
2904 image()->filename[ fileName_.length() ] = 0; // Null terminate
2905
2906 options()->fileName( fileName_ );
2907
2908}
2909std::string Magick::Image::fileName ( void ) const
2910{
2911 return constOptions()->fileName( );
2912}
2913
2914// Image file size
2915off_t Magick::Image::fileSize ( void ) const
2916{
2917 return (off_t) GetBlobSize( constImage() );
2918}
2919
2920// Color to use when drawing inside an object
2921void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
2922{
2923 modifyImage();
2924 options()->fillColor(fillColor_);
2925}
2926Magick::Color Magick::Image::fillColor ( void ) const
2927{
2928 return constOptions()->fillColor();
2929}
2930
2931// Rule to use when filling drawn objects
2932void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
2933{
2934 modifyImage();
2935 options()->fillRule(fillRule_);
2936}
2937Magick::FillRule Magick::Image::fillRule ( void ) const
2938{
2939 return constOptions()->fillRule();
2940}
2941
2942// Pattern to use while filling drawn objects.
2943void Magick::Image::fillPattern ( const Image &fillPattern_ )
2944{
2945 modifyImage();
2946 if(fillPattern_.isValid())
2947 options()->fillPattern( fillPattern_.constImage() );
2948 else
2949 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
2950}
2951Magick::Image Magick::Image::fillPattern ( void ) const
2952{
2953 // FIXME: This is inordinately innefficient
2954 Image texture;
2955
2956 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
2957
2958 if ( tmpTexture )
2959 {
2960 ExceptionInfo exceptionInfo;
2961 GetExceptionInfo( &exceptionInfo );
2962 MagickCore::Image* image =
2963 CloneImage( tmpTexture,
2964 0, // columns
2965 0, // rows
2966 MagickTrue, // orphan
2967 &exceptionInfo);
2968 texture.replaceImage( image );
2969 throwException( exceptionInfo );
2970 (void) DestroyExceptionInfo( &exceptionInfo );
2971 }
2972 return texture;
2973}
2974
2975// Filter used by zoom
2976void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
2977{
2978 modifyImage();
2979 image()->filter = filterType_;
2980}
2981Magick::FilterTypes Magick::Image::filterType ( void ) const
2982{
2983 return constImage()->filter;
2984}
2985
2986// Font name
2987void Magick::Image::font ( const std::string &font_ )
2988{
2989 modifyImage();
2990 options()->font( font_ );
2991}
2992std::string Magick::Image::font ( void ) const
2993{
2994 return constOptions()->font( );
2995}
2996
2997// Font point size
2998void Magick::Image::fontPointsize ( const double pointSize_ )
2999{
3000 modifyImage();
3001 options()->fontPointsize( pointSize_ );
3002}
3003double Magick::Image::fontPointsize ( void ) const
3004{
3005 return constOptions()->fontPointsize( );
3006}
3007
3008// Font type metrics
3009void Magick::Image::fontTypeMetrics( const std::string &text_,
3010 TypeMetric *metrics )
3011{
3012 DrawInfo *drawInfo = options()->drawInfo();
3013 drawInfo->text = const_cast<char *>(text_.c_str());
3014 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
3015 drawInfo->text = 0;
3016}
3017
3018// Image format string
3019std::string Magick::Image::format ( void ) const
3020{
3021 ExceptionInfo exceptionInfo;
3022 GetExceptionInfo( &exceptionInfo );
3023 const MagickInfo * magick_info
3024 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3025 throwException( exceptionInfo );
3026 (void) DestroyExceptionInfo( &exceptionInfo );
3027
3028 if (( magick_info != 0 ) &&
3029 ( *magick_info->description != '\0' ))
3030 return std::string(magick_info->description);
3031
3032 throwExceptionExplicit( CorruptImageWarning,
3033 "Unrecognized image magick type" );
3034 return std::string();
3035}
3036
3037// Gamma adjustment
3038double Magick::Image::gamma ( void ) const
3039{
3040 return constImage()->gamma;
3041}
3042
3043Magick::Geometry Magick::Image::geometry ( void ) const
3044{
3045 if ( constImage()->geometry )
3046 {
3047 return Geometry(constImage()->geometry);
3048 }
3049
3050 throwExceptionExplicit( OptionWarning,
3051 "Image does not contain a geometry");
3052
3053 return Geometry();
3054}
3055
cristyeaedf062010-05-29 22:36:02 +00003056void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
cristy3ed852e2009-09-05 21:47:34 +00003057{
3058 modifyImage();
3059 image()->dispose = (DisposeType) disposeMethod_;
3060}
cristyeaedf062010-05-29 22:36:02 +00003061size_t Magick::Image::gifDisposeMethod ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003062{
3063 // FIXME: It would be better to return an enumeration
3064 return constImage()->dispose;
3065}
3066
3067// ICC ICM color profile (BLOB)
3068void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3069{
3070 profile("icm",colorProfile_);
3071}
3072Magick::Blob Magick::Image::iccColorProfile( void ) const
3073{
3074 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3075 if ( color_profile == (StringInfo *) NULL)
3076 return Blob( 0, 0 );
3077 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3078}
3079
3080void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3081{
3082 modifyImage();
3083 image()->interlace = interlace_;
3084 options()->interlaceType ( interlace_ );
3085}
3086Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3087{
3088 return constImage()->interlace;
3089}
3090
3091// IPTC profile (BLOB)
3092void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3093{
3094 modifyImage();
3095 if ( iptcProfile_.data() != 0 )
3096 {
3097 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3098 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3099 (void) SetImageProfile( image(), "iptc", iptc_profile);
3100 iptc_profile =DestroyStringInfo( iptc_profile );
3101 }
3102}
3103Magick::Blob Magick::Image::iptcProfile( void ) const
3104{
3105 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3106 if ( iptc_profile == (StringInfo *) NULL)
3107 return Blob( 0, 0 );
3108 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3109}
3110
3111// Does object contain valid image?
3112void Magick::Image::isValid ( const bool isValid_ )
3113{
3114 if ( !isValid_ )
3115 {
3116 delete _imgRef;
3117 _imgRef = new ImageRef;
3118 }
3119 else if ( !isValid() )
3120 {
3121 // Construct with single-pixel black image to make
3122 // image valid. This is an obvious hack.
3123 size( Geometry(1,1) );
3124 read( "xc:#000000" );
3125 }
3126}
3127
3128bool Magick::Image::isValid ( void ) const
3129{
3130 if ( rows() && columns() )
3131 return true;
3132
3133 return false;
3134}
3135
3136// Label image
3137void Magick::Image::label ( const std::string &label_ )
3138{
3139 modifyImage();
3140 SetImageProperty ( image(), "Label", NULL );
3141 if ( label_.length() > 0 )
3142 SetImageProperty ( image(), "Label", label_.c_str() );
3143 throwImageException();
3144}
3145std::string Magick::Image::label ( void ) const
3146{
3147 const char *value = GetImageProperty( constImage(), "Label" );
3148
3149 if ( value )
3150 return std::string( value );
3151
3152 return std::string();
3153}
3154
3155void Magick::Image::magick ( const std::string &magick_ )
3156{
3157 modifyImage();
3158
3159 magick_.copy( image()->magick,
3160 sizeof(image()->magick) - 1 );
3161 image()->magick[ magick_.length() ] = 0;
3162
3163 options()->magick( magick_ );
3164}
3165std::string Magick::Image::magick ( void ) const
3166{
3167 if ( *(constImage()->magick) != '\0' )
3168 return std::string(constImage()->magick);
3169
3170 return constOptions()->magick( );
3171}
3172
3173void Magick::Image::matte ( const bool matteFlag_ )
3174{
3175 modifyImage();
3176
3177 // If matte channel is requested, but image doesn't already have a
3178 // matte channel, then create an opaque matte channel. Likewise, if
3179 // the image already has a matte channel but a matte channel is not
3180 // desired, then set the matte channel to opaque.
3181 if ((matteFlag_ && !constImage()->matte) ||
3182 (constImage()->matte && !matteFlag_))
cristy4c08aed2011-07-01 19:47:50 +00003183 SetImageOpacity(image(),OpaqueAlpha);
cristy3ed852e2009-09-05 21:47:34 +00003184
3185 image()->matte = (MagickBooleanType) matteFlag_;
3186}
3187bool Magick::Image::matte ( void ) const
3188{
3189 if ( constImage()->matte )
3190 return true;
3191 else
3192 return false;
3193}
3194
3195void Magick::Image::matteColor ( const Color &matteColor_ )
3196{
3197 modifyImage();
3198
3199 if ( matteColor_.isValid() )
3200 {
cristy391f1ce2010-09-09 17:23:28 +00003201 image()->matte_color = matteColor_;
3202 options()->matteColor( matteColor_ );
cristy3ed852e2009-09-05 21:47:34 +00003203 }
3204 else
3205 {
3206 // Set to default matte color
3207 Color tmpColor( "#BDBDBD" );
cristy391f1ce2010-09-09 17:23:28 +00003208 image()->matte_color = tmpColor;
cristy3ed852e2009-09-05 21:47:34 +00003209 options()->matteColor( tmpColor );
3210 }
3211}
3212Magick::Color Magick::Image::matteColor ( void ) const
3213{
3214 return Color( constImage()->matte_color.red,
3215 constImage()->matte_color.green,
cristy391f1ce2010-09-09 17:23:28 +00003216 constImage()->matte_color.blue );
cristy3ed852e2009-09-05 21:47:34 +00003217}
3218
3219double Magick::Image::meanErrorPerPixel ( void ) const
3220{
3221 return(constImage()->error.mean_error_per_pixel);
3222}
3223
3224// Image modulus depth (minimum number of bits required to support
3225// red/green/blue components without loss of accuracy)
cristyeaedf062010-05-29 22:36:02 +00003226void Magick::Image::modulusDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00003227{
3228 modifyImage();
3229 SetImageDepth( image(), depth_ );
3230 options()->depth( depth_ );
3231}
cristyeaedf062010-05-29 22:36:02 +00003232size_t Magick::Image::modulusDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003233{
3234 ExceptionInfo exceptionInfo;
3235 GetExceptionInfo( &exceptionInfo );
cristyeaedf062010-05-29 22:36:02 +00003236 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003237 throwException( exceptionInfo );
3238 (void) DestroyExceptionInfo( &exceptionInfo );
3239 return depth;
3240}
3241
3242void Magick::Image::monochrome ( const bool monochromeFlag_ )
3243{
3244 modifyImage();
3245 options()->monochrome( monochromeFlag_ );
3246}
3247bool Magick::Image::monochrome ( void ) const
3248{
3249 return constOptions()->monochrome( );
3250}
3251
3252Magick::Geometry Magick::Image::montageGeometry ( void ) const
3253{
3254 if ( constImage()->montage )
3255 return Magick::Geometry(constImage()->montage);
3256
3257 throwExceptionExplicit( CorruptImageWarning,
3258 "Image does not contain a montage" );
3259
3260 return Magick::Geometry();
3261}
3262
3263double Magick::Image::normalizedMaxError ( void ) const
3264{
3265 return(constImage()->error.normalized_maximum_error);
3266}
3267
3268double Magick::Image::normalizedMeanError ( void ) const
3269{
3270 return constImage()->error.normalized_mean_error;
3271}
3272
3273// Image orientation
3274void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3275{
3276 modifyImage();
3277 image()->orientation = orientation_;
3278}
3279Magick::OrientationType Magick::Image::orientation ( void ) const
3280{
3281 return constImage()->orientation;
3282}
3283
3284void Magick::Image::penColor ( const Color &penColor_ )
3285{
3286 modifyImage();
3287 options()->fillColor(penColor_);
3288 options()->strokeColor(penColor_);
3289}
3290Magick::Color Magick::Image::penColor ( void ) const
3291{
3292 return constOptions()->fillColor();
3293}
3294
3295void Magick::Image::penTexture ( const Image &penTexture_ )
3296{
3297 modifyImage();
3298 if(penTexture_.isValid())
3299 options()->fillPattern( penTexture_.constImage() );
3300 else
3301 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3302}
3303
3304Magick::Image Magick::Image::penTexture ( void ) const
3305{
3306 // FIXME: This is inordinately innefficient
3307 Image texture;
3308
3309 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3310
3311 if ( tmpTexture )
3312 {
3313 ExceptionInfo exceptionInfo;
3314 GetExceptionInfo( &exceptionInfo );
3315 MagickCore::Image* image =
3316 CloneImage( tmpTexture,
3317 0, // columns
3318 0, // rows
3319 MagickTrue, // orphan
3320 &exceptionInfo);
3321 texture.replaceImage( image );
3322 throwException( exceptionInfo );
3323 (void) DestroyExceptionInfo( &exceptionInfo );
3324 }
3325 return texture;
3326}
3327
3328// Set the color of a pixel.
cristy35ef8242010-06-03 16:24:13 +00003329void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00003330 const Color &color_ )
3331{
3332 // Test arguments to ensure they are within the image.
cristy07fb9182010-06-06 23:37:14 +00003333 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
cristy3ed852e2009-09-05 21:47:34 +00003334 throwExceptionExplicit( OptionError,
3335 "Access outside of image boundary" );
3336
3337 modifyImage();
3338
3339 // Set image to DirectClass
3340 classType( DirectClass );
3341
3342 // Get pixel view
3343 Pixels pixels(*this);
3344 // Set pixel value
cristy4c08aed2011-07-01 19:47:50 +00003345 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3346 PixelPacket packet = color_;
3347 MagickCore::SetPixelPacket(constImage(),&packet,pixel);
cristy3ed852e2009-09-05 21:47:34 +00003348 // Tell ImageMagick that pixels have been updated
3349 pixels.sync();
3350
3351 return;
3352}
3353
3354// Get the color of a pixel
cristy35ef8242010-06-03 16:24:13 +00003355Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3356 const ssize_t y_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003357{
3358 ClassType storage_class;
3359 storage_class = classType();
3360 // DirectClass
cristy4c08aed2011-07-01 19:47:50 +00003361 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3362 if ( pixel )
cristy3ed852e2009-09-05 21:47:34 +00003363 {
cristy4c08aed2011-07-01 19:47:50 +00003364 PixelPacket packet;
3365 MagickCore::GetPixelPacket(constImage(),pixel,&packet);
3366 return Color( packet );
cristy3ed852e2009-09-05 21:47:34 +00003367 }
3368
3369 return Color(); // invalid
3370}
3371
3372// Preferred size and location of an image canvas.
3373void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3374{
3375 modifyImage();
3376 options()->page( pageSize_ );
3377 image()->page = pageSize_;
3378}
3379Magick::Geometry Magick::Image::page ( void ) const
3380{
3381 return Geometry( constImage()->page.width,
3382 constImage()->page.height,
3383 AbsoluteValue(constImage()->page.x),
3384 AbsoluteValue(constImage()->page.y),
3385 constImage()->page.x < 0 ? true : false,
3386 constImage()->page.y < 0 ? true : false);
3387}
3388
3389// Add a named profile to an image or remove a named profile by
3390// passing an empty Blob (use default Blob constructor).
3391// Valid names are:
3392// "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3393void Magick::Image::profile( const std::string name_,
3394 const Magick::Blob &profile_ )
3395{
3396 modifyImage();
cristyd99b0962010-05-29 23:14:26 +00003397 ssize_t result = ProfileImage( image(), name_.c_str(),
cristy3ed852e2009-09-05 21:47:34 +00003398 (unsigned char *)profile_.data(),
3399 profile_.length(), MagickTrue);
3400
3401 if( !result )
3402 throwImageException();
3403}
3404
3405// Retrieve a named profile from the image.
3406// Valid names are:
3407// "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3408// an existing generic profile name.
3409Magick::Blob Magick::Image::profile( const std::string name_ ) const
3410{
3411 const MagickCore::Image* image = constImage();
3412
3413 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3414
3415 if ( profile != (StringInfo *) NULL)
3416 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3417
3418 Blob blob;
3419 Image temp_image = *this;
3420 temp_image.write( &blob, name_ );
3421 return blob;
3422}
3423
cristyeaedf062010-05-29 22:36:02 +00003424void Magick::Image::quality ( const size_t quality_ )
cristy3ed852e2009-09-05 21:47:34 +00003425{
3426 modifyImage();
3427 image()->quality = quality_;
3428 options()->quality( quality_ );
3429}
cristyeaedf062010-05-29 22:36:02 +00003430size_t Magick::Image::quality ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003431{
3432 return constImage()->quality;
3433}
3434
cristyeaedf062010-05-29 22:36:02 +00003435void Magick::Image::quantizeColors ( const size_t colors_ )
cristy3ed852e2009-09-05 21:47:34 +00003436{
3437 modifyImage();
3438 options()->quantizeColors( colors_ );
3439}
cristyeaedf062010-05-29 22:36:02 +00003440size_t Magick::Image::quantizeColors ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003441{
3442 return constOptions()->quantizeColors( );
3443}
3444
3445void Magick::Image::quantizeColorSpace
3446 ( const Magick::ColorspaceType colorSpace_ )
3447{
3448 modifyImage();
3449 options()->quantizeColorSpace( colorSpace_ );
3450}
3451Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3452{
3453 return constOptions()->quantizeColorSpace( );
3454}
3455
3456void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3457{
3458 modifyImage();
3459 options()->quantizeDither( ditherFlag_ );
3460}
3461bool Magick::Image::quantizeDither ( void ) const
3462{
3463 return constOptions()->quantizeDither( );
3464}
3465
cristyeaedf062010-05-29 22:36:02 +00003466void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
cristy3ed852e2009-09-05 21:47:34 +00003467{
3468 modifyImage();
3469 options()->quantizeTreeDepth( treeDepth_ );
3470}
cristyeaedf062010-05-29 22:36:02 +00003471size_t Magick::Image::quantizeTreeDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003472{
3473 return constOptions()->quantizeTreeDepth( );
3474}
3475
3476void Magick::Image::renderingIntent
3477 ( const Magick::RenderingIntent renderingIntent_ )
3478{
3479 modifyImage();
3480 image()->rendering_intent = renderingIntent_;
3481}
3482Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3483{
3484 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3485}
3486
3487void Magick::Image::resolutionUnits
3488 ( const Magick::ResolutionType resolutionUnits_ )
3489{
3490 modifyImage();
3491 image()->units = resolutionUnits_;
3492 options()->resolutionUnits( resolutionUnits_ );
3493}
3494Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3495{
3496 return constOptions()->resolutionUnits( );
3497}
3498
cristyeaedf062010-05-29 22:36:02 +00003499void Magick::Image::scene ( const size_t scene_ )
cristy3ed852e2009-09-05 21:47:34 +00003500{
3501 modifyImage();
3502 image()->scene = scene_;
3503}
cristyeaedf062010-05-29 22:36:02 +00003504size_t Magick::Image::scene ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003505{
3506 return constImage()->scene;
3507}
3508
3509std::string Magick::Image::signature ( const bool force_ ) const
3510{
3511 Lock( &_imgRef->_mutexLock );
3512
3513 // Re-calculate image signature if necessary
3514 if ( force_ ||
3515 !GetImageProperty(constImage(), "Signature") ||
3516 constImage()->taint )
3517 {
3518 SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
3519 }
3520
3521 const char *property = GetImageProperty(constImage(), "Signature");
3522
3523 return std::string( property );
3524}
3525
3526void Magick::Image::size ( const Geometry &geometry_ )
3527{
3528 modifyImage();
3529 options()->size( geometry_ );
3530 image()->rows = geometry_.height();
3531 image()->columns = geometry_.width();
3532}
3533Magick::Geometry Magick::Image::size ( void ) const
3534{
3535 return Magick::Geometry( constImage()->columns, constImage()->rows );
3536}
3537
cristy8198a752009-09-28 23:59:24 +00003538// Splice image
3539void Magick::Image::splice( const Geometry &geometry_ )
3540{
3541 RectangleInfo spliceInfo = geometry_;
3542 ExceptionInfo exceptionInfo;
3543 GetExceptionInfo( &exceptionInfo );
3544 MagickCore::Image* newImage =
3545 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3546 replaceImage( newImage );
3547 throwException( exceptionInfo );
3548 (void) DestroyExceptionInfo( &exceptionInfo );
3549}
3550
cristy3ed852e2009-09-05 21:47:34 +00003551// Obtain image statistics. Statistics are normalized to the range of
3552// 0.0 to 1.0 and are output to the specified ImageStatistics
3553// structure.
3554void Magick::Image::statistics ( ImageStatistics *statistics ) const
3555{
3556 double
3557 maximum,
3558 minimum;
3559
3560 ExceptionInfo exceptionInfo;
3561 GetExceptionInfo( &exceptionInfo );
3562 (void) GetImageChannelRange(constImage(),RedChannel,&minimum,&maximum,
3563 &exceptionInfo);
3564 statistics->red.minimum=minimum;
3565 statistics->red.maximum=maximum;
3566 (void) GetImageChannelMean(constImage(),RedChannel,
3567 &statistics->red.mean,&statistics->red.standard_deviation,&exceptionInfo);
3568 (void) GetImageChannelKurtosis(constImage(),RedChannel,
3569 &statistics->red.kurtosis,&statistics->red.skewness,&exceptionInfo);
3570 (void) GetImageChannelRange(constImage(),GreenChannel,&minimum,&maximum,
3571 &exceptionInfo);
3572 statistics->green.minimum=minimum;
3573 statistics->green.maximum=maximum;
3574 (void) GetImageChannelMean(constImage(),GreenChannel,
3575 &statistics->green.mean,&statistics->green.standard_deviation,
3576 &exceptionInfo);
3577 (void) GetImageChannelKurtosis(constImage(),GreenChannel,
3578 &statistics->green.kurtosis,&statistics->green.skewness,&exceptionInfo);
3579 (void) GetImageChannelRange(constImage(),BlueChannel,&minimum,&maximum,
3580 &exceptionInfo);
3581 statistics->blue.minimum=minimum;
3582 statistics->blue.maximum=maximum;
3583 (void) GetImageChannelMean(constImage(),BlueChannel,
3584 &statistics->blue.mean,&statistics->blue.standard_deviation,&exceptionInfo);
3585 (void) GetImageChannelKurtosis(constImage(),BlueChannel,
3586 &statistics->blue.kurtosis,&statistics->blue.skewness,&exceptionInfo);
3587 (void) GetImageChannelRange(constImage(),OpacityChannel,&minimum,&maximum,
3588 &exceptionInfo);
cristy4c08aed2011-07-01 19:47:50 +00003589 statistics->alpha.minimum=minimum;
3590 statistics->alpha.maximum=maximum;
cristy3ed852e2009-09-05 21:47:34 +00003591 (void) GetImageChannelMean(constImage(),OpacityChannel,
cristy4c08aed2011-07-01 19:47:50 +00003592 &statistics->alpha.mean,&statistics->alpha.standard_deviation,
cristy3ed852e2009-09-05 21:47:34 +00003593 &exceptionInfo);
3594 (void) GetImageChannelKurtosis(constImage(),OpacityChannel,
cristy4c08aed2011-07-01 19:47:50 +00003595 &statistics->alpha.kurtosis,&statistics->alpha.skewness,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003596 throwException( exceptionInfo );
3597 (void) DestroyExceptionInfo( &exceptionInfo );
3598}
3599
cristy9f89a3f2011-02-12 17:02:35 +00003600// Strip strips an image of all profiles and comments.
3601void Magick::Image::strip ( void )
3602{
3603 modifyImage();
3604 StripImage( image() );
3605 throwImageException();
3606}
3607
cristy3ed852e2009-09-05 21:47:34 +00003608// enabled/disable stroke anti-aliasing
3609void Magick::Image::strokeAntiAlias ( const bool flag_ )
3610{
3611 modifyImage();
3612 options()->strokeAntiAlias(flag_);
3613}
3614bool Magick::Image::strokeAntiAlias ( void ) const
3615{
3616 return constOptions()->strokeAntiAlias();
3617}
3618
3619// Color to use when drawing object outlines
3620void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3621{
3622 modifyImage();
3623 options()->strokeColor(strokeColor_);
3624}
3625Magick::Color Magick::Image::strokeColor ( void ) const
3626{
3627 return constOptions()->strokeColor();
3628}
3629
3630// dash pattern for drawing vector objects (default one)
3631void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3632{
3633 modifyImage();
3634 options()->strokeDashArray( strokeDashArray_ );
3635}
3636
3637const double* Magick::Image::strokeDashArray ( void ) const
3638{
3639 return constOptions()->strokeDashArray( );
3640}
3641
3642// dash offset for drawing vector objects (default one)
3643void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3644{
3645 modifyImage();
3646 options()->strokeDashOffset( strokeDashOffset_ );
3647}
3648
3649double Magick::Image::strokeDashOffset ( void ) const
3650{
3651 return constOptions()->strokeDashOffset( );
3652}
3653
3654// Specify the shape to be used at the end of open subpaths when they
3655// are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3656// and SquareCap.
3657void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3658{
3659 modifyImage();
3660 options()->strokeLineCap( lineCap_ );
3661}
3662Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3663{
3664 return constOptions()->strokeLineCap( );
3665}
3666
3667// Specify the shape to be used at the corners of paths (or other
3668// vector shapes) when they are stroked. Values of LineJoin are
3669// UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3670void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3671{
3672 modifyImage();
3673 options()->strokeLineJoin( lineJoin_ );
3674}
3675Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3676{
3677 return constOptions()->strokeLineJoin( );
3678}
3679
3680// Specify miter limit. When two line segments meet at a sharp angle
3681// and miter joins have been specified for 'lineJoin', it is possible
3682// for the miter to extend far beyond the thickness of the line
3683// stroking the path. The miterLimit' imposes a limit on the ratio of
3684// the miter length to the 'lineWidth'. The default value of this
3685// parameter is 4.
cristyeaedf062010-05-29 22:36:02 +00003686void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
cristy3ed852e2009-09-05 21:47:34 +00003687{
3688 modifyImage();
3689 options()->strokeMiterLimit( strokeMiterLimit_ );
3690}
cristyeaedf062010-05-29 22:36:02 +00003691size_t Magick::Image::strokeMiterLimit ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003692{
3693 return constOptions()->strokeMiterLimit( );
3694}
3695
3696// Pattern to use while stroking drawn objects.
3697void Magick::Image::strokePattern ( const Image &strokePattern_ )
3698{
3699 modifyImage();
3700 if(strokePattern_.isValid())
3701 options()->strokePattern( strokePattern_.constImage() );
3702 else
3703 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3704}
3705Magick::Image Magick::Image::strokePattern ( void ) const
3706{
3707 // FIXME: This is inordinately innefficient
3708 Image texture;
3709
3710 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3711
3712 if ( tmpTexture )
3713 {
3714 ExceptionInfo exceptionInfo;
3715 GetExceptionInfo( &exceptionInfo );
3716 MagickCore::Image* image =
3717 CloneImage( tmpTexture,
3718 0, // columns
3719 0, // rows
3720 MagickTrue, // orphan
3721 &exceptionInfo);
3722 throwException( exceptionInfo );
3723 (void) DestroyExceptionInfo( &exceptionInfo );
3724 texture.replaceImage( image );
3725 }
3726 return texture;
3727}
3728
3729// Stroke width for drawing lines, circles, ellipses, etc.
3730void Magick::Image::strokeWidth ( const double strokeWidth_ )
3731{
3732 modifyImage();
3733 options()->strokeWidth( strokeWidth_ );
3734}
3735double Magick::Image::strokeWidth ( void ) const
3736{
3737 return constOptions()->strokeWidth( );
3738}
3739
cristyeaedf062010-05-29 22:36:02 +00003740void Magick::Image::subImage ( const size_t subImage_ )
cristy3ed852e2009-09-05 21:47:34 +00003741{
3742 modifyImage();
3743 options()->subImage( subImage_ );
3744}
cristyeaedf062010-05-29 22:36:02 +00003745size_t Magick::Image::subImage ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003746{
3747 return constOptions()->subImage( );
3748}
3749
cristyeaedf062010-05-29 22:36:02 +00003750void Magick::Image::subRange ( const size_t subRange_ )
cristy3ed852e2009-09-05 21:47:34 +00003751{
3752 modifyImage();
3753 options()->subRange( subRange_ );
3754}
cristyeaedf062010-05-29 22:36:02 +00003755size_t Magick::Image::subRange ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003756{
3757 return constOptions()->subRange( );
3758}
3759
3760// Annotation text encoding (e.g. "UTF-16")
3761void Magick::Image::textEncoding ( const std::string &encoding_ )
3762{
3763 modifyImage();
3764 options()->textEncoding( encoding_ );
3765}
3766std::string Magick::Image::textEncoding ( void ) const
3767{
3768 return constOptions()->textEncoding( );
3769}
3770
cristybb503372010-05-27 20:51:26 +00003771size_t Magick::Image::totalColors ( void )
cristy3ed852e2009-09-05 21:47:34 +00003772{
3773 ExceptionInfo exceptionInfo;
3774 GetExceptionInfo( &exceptionInfo );
cristybb503372010-05-27 20:51:26 +00003775 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003776 throwException( exceptionInfo );
3777 (void) DestroyExceptionInfo( &exceptionInfo );
3778 return colors;
3779}
3780
3781// Origin of coordinate system to use when annotating with text or drawing
3782void Magick::Image::transformOrigin ( const double x_, const double y_ )
3783{
3784 modifyImage();
3785 options()->transformOrigin( x_, y_ );
3786}
3787
3788// Rotation to use when annotating with text or drawing
3789void Magick::Image::transformRotation ( const double angle_ )
3790{
3791 modifyImage();
3792 options()->transformRotation( angle_ );
3793}
3794
3795// Reset transformation parameters to default
3796void Magick::Image::transformReset ( void )
3797{
3798 modifyImage();
3799 options()->transformReset();
3800}
3801
3802// Scale to use when annotating with text or drawing
3803void Magick::Image::transformScale ( const double sx_, const double sy_ )
3804{
3805 modifyImage();
3806 options()->transformScale( sx_, sy_ );
3807}
3808
3809// Skew to use in X axis when annotating with text or drawing
3810void Magick::Image::transformSkewX ( const double skewx_ )
3811{
3812 modifyImage();
3813 options()->transformSkewX( skewx_ );
3814}
3815
3816// Skew to use in Y axis when annotating with text or drawing
3817void Magick::Image::transformSkewY ( const double skewy_ )
3818{
3819 modifyImage();
3820 options()->transformSkewY( skewy_ );
3821}
3822
3823// Image representation type
3824Magick::ImageType Magick::Image::type ( void ) const
3825{
3826
3827 ExceptionInfo exceptionInfo;
3828 GetExceptionInfo( &exceptionInfo );
3829 ImageType image_type = constOptions()->type();
3830 if ( image_type == UndefinedType )
3831 image_type= GetImageType( constImage(), &exceptionInfo);
3832 throwException( exceptionInfo );
3833 (void) DestroyExceptionInfo( &exceptionInfo );
3834 return image_type;
3835}
3836void Magick::Image::type ( const Magick::ImageType type_)
3837{
3838 modifyImage();
3839 options()->type( type_ );
3840 SetImageType( image(), type_ );
3841}
3842
3843void Magick::Image::verbose ( const bool verboseFlag_ )
3844{
3845 modifyImage();
3846 options()->verbose( verboseFlag_ );
3847}
3848bool Magick::Image::verbose ( void ) const
3849{
3850 return constOptions()->verbose( );
3851}
3852
3853void Magick::Image::view ( const std::string &view_ )
3854{
3855 modifyImage();
3856 options()->view( view_ );
3857}
3858std::string Magick::Image::view ( void ) const
3859{
3860 return constOptions()->view( );
3861}
3862
3863// Virtual pixel method
3864void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
3865{
3866 modifyImage();
3867 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
3868 options()->virtualPixelMethod( virtual_pixel_method_ );
3869}
3870Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
3871{
3872 return GetImageVirtualPixelMethod( constImage() );
3873}
3874
3875void Magick::Image::x11Display ( const std::string &display_ )
3876{
3877 modifyImage();
3878 options()->x11Display( display_ );
3879}
3880std::string Magick::Image::x11Display ( void ) const
3881{
3882 return constOptions()->x11Display( );
3883}
3884
3885double Magick::Image::xResolution ( void ) const
3886{
3887 return constImage()->x_resolution;
3888}
3889double Magick::Image::yResolution ( void ) const
3890{
3891 return constImage()->y_resolution;
3892}
3893
3894// Copy Constructor
3895Magick::Image::Image( const Image & image_ )
3896 : _imgRef(image_._imgRef)
3897{
3898 Lock( &_imgRef->_mutexLock );
3899
3900 // Increase reference count
3901 ++_imgRef->_refCount;
3902}
3903
3904// Assignment operator
3905Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
3906{
3907 if( this != &image_ )
3908 {
3909 {
3910 Lock( &image_._imgRef->_mutexLock );
3911 ++image_._imgRef->_refCount;
3912 }
3913
3914 bool doDelete = false;
3915 {
3916 Lock( &_imgRef->_mutexLock );
3917 if ( --_imgRef->_refCount == 0 )
3918 doDelete = true;
3919 }
3920
3921 if ( doDelete )
3922 {
3923 // Delete old image reference with associated image and options.
3924 delete _imgRef;
3925 _imgRef = 0;
3926 }
3927 // Use new image reference
3928 _imgRef = image_._imgRef;
3929 }
3930
3931 return *this;
3932}
3933
3934//////////////////////////////////////////////////////////////////////
3935//
3936// Low-level Pixel Access Routines
3937//
3938// Also see the Pixels class, which provides support for multiple
3939// cache views. The low-level pixel access routines in the Image
3940// class are provided in order to support backward compatability.
3941//
3942//////////////////////////////////////////////////////////////////////
3943
3944// Transfers read-only pixels from the image to the pixel cache as
3945// defined by the specified region
cristy4c08aed2011-07-01 19:47:50 +00003946const Magick::Quantum* Magick::Image::getConstPixels
cristyd99b0962010-05-29 23:14:26 +00003947 ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00003948 const size_t columns_,
3949 const size_t rows_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003950{
3951 ExceptionInfo exceptionInfo;
3952 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00003953 const Quantum* p = (*GetVirtualPixels)( constImage(),
cristy3ed852e2009-09-05 21:47:34 +00003954 x_, y_,
3955 columns_, rows_,
3956 &exceptionInfo );
3957 throwException( exceptionInfo );
3958 (void) DestroyExceptionInfo( &exceptionInfo );
3959 return p;
3960}
3961
cristy4c08aed2011-07-01 19:47:50 +00003962// Obtain read-only pixel associated pixels channels
3963const void* Magick::Image::getConstMetacontent ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003964{
cristy4c08aed2011-07-01 19:47:50 +00003965 const void* result = GetVirtualMetacontent( constImage() );
cristy3ed852e2009-09-05 21:47:34 +00003966
3967 if( !result )
3968 throwImageException();
3969
3970 return result;
3971}
3972
cristy4c08aed2011-07-01 19:47:50 +00003973// Obtain image pixel associated pixels channels
3974void* Magick::Image::getMetacontent ( void )
cristy3ed852e2009-09-05 21:47:34 +00003975{
cristy4c08aed2011-07-01 19:47:50 +00003976 void* result = GetAuthenticMetacontent( image() );
cristy3ed852e2009-09-05 21:47:34 +00003977
3978 if( !result )
3979 throwImageException();
3980
3981 return ( result );
3982}
3983
3984// Transfers pixels from the image to the pixel cache as defined
3985// by the specified region. Modified pixels may be subsequently
3986// transferred back to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00003987Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00003988 const size_t columns_,
3989 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00003990{
3991 modifyImage();
3992 ExceptionInfo exceptionInfo;
3993 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00003994 Quantum* result = (*GetAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00003995 x_, y_,
3996 columns_, rows_, &exceptionInfo );
3997 throwException( exceptionInfo );
3998 (void) DestroyExceptionInfo( &exceptionInfo );
3999
4000 return result;
4001}
4002
4003// Allocates a pixel cache region to store image pixels as defined
4004// by the region rectangle. This area is subsequently transferred
4005// from the pixel cache to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00004006Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00004007 const size_t columns_,
4008 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00004009{
4010 modifyImage();
4011 ExceptionInfo exceptionInfo;
4012 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00004013 Quantum* result = (*QueueAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00004014 x_, y_,
4015 columns_, rows_, &exceptionInfo );
4016 throwException( exceptionInfo );
4017 (void) DestroyExceptionInfo( &exceptionInfo );
4018
4019 return result;
4020}
4021
4022// Transfers the image cache pixels to the image.
4023void Magick::Image::syncPixels ( void )
4024{
4025 ExceptionInfo exceptionInfo;
4026 GetExceptionInfo( &exceptionInfo );
4027 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4028 throwException( exceptionInfo );
4029 (void) DestroyExceptionInfo( &exceptionInfo );
4030}
4031
4032// Transfers one or more pixel components from a buffer or file
4033// into the image pixel cache of an image.
4034// Used to support image decoders.
4035void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4036 const unsigned char *source_ )
4037{
4038 QuantumInfo
4039 *quantum_info;
4040
4041 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4042 ExceptionInfo exceptionInfo;
4043 GetExceptionInfo( &exceptionInfo );
4044 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4045 quantum_,source_, &exceptionInfo);
4046 throwException( exceptionInfo );
4047 (void) DestroyExceptionInfo( &exceptionInfo );
4048 quantum_info=DestroyQuantumInfo(quantum_info);
4049}
4050
4051// Transfers one or more pixel components from the image pixel
4052// cache to a buffer or file.
4053// Used to support image encoders.
4054void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4055 unsigned char *destination_ )
4056{
4057 QuantumInfo
4058 *quantum_info;
4059
4060 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4061 ExceptionInfo exceptionInfo;
4062 GetExceptionInfo( &exceptionInfo );
4063 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4064 quantum_,destination_, &exceptionInfo);
4065 quantum_info=DestroyQuantumInfo(quantum_info);
4066 throwException( exceptionInfo );
4067 (void) DestroyExceptionInfo( &exceptionInfo );
4068}
4069
4070/////////////////////////////////////////////////////////////////////
4071//
4072// No end-user methods beyond this point
4073//
4074/////////////////////////////////////////////////////////////////////
4075
4076
4077//
4078// Construct using existing image and default options
4079//
4080Magick::Image::Image ( MagickCore::Image* image_ )
4081 : _imgRef(new ImageRef( image_))
4082{
4083}
4084
4085// Get Magick::Options*
4086Magick::Options* Magick::Image::options( void )
4087{
4088 return _imgRef->options();
4089}
4090const Magick::Options* Magick::Image::constOptions( void ) const
4091{
4092 return _imgRef->options();
4093}
4094
4095// Get MagickCore::Image*
4096MagickCore::Image*& Magick::Image::image( void )
4097{
4098 return _imgRef->image();
4099}
4100const MagickCore::Image* Magick::Image::constImage( void ) const
4101{
4102 return _imgRef->image();
4103}
4104
4105// Get ImageInfo *
4106MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4107{
4108 return _imgRef->options()->imageInfo();
4109}
4110const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4111{
4112 return _imgRef->options()->imageInfo();
4113}
4114
4115// Get QuantizeInfo *
4116MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4117{
4118 return _imgRef->options()->quantizeInfo();
4119}
4120const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4121{
4122 return _imgRef->options()->quantizeInfo();
4123}
4124
4125//
4126// Replace current image
4127//
4128MagickCore::Image * Magick::Image::replaceImage
4129 ( MagickCore::Image* replacement_ )
4130{
4131 MagickCore::Image* image;
4132
4133 if( replacement_ )
4134 image = replacement_;
4135 else
4136 image = AcquireImage(constImageInfo());
4137
4138 {
4139 Lock( &_imgRef->_mutexLock );
4140
4141 if ( _imgRef->_refCount == 1 )
4142 {
4143 // We own the image, just replace it, and de-register
4144 _imgRef->id( -1 );
4145 _imgRef->image(image);
4146 }
4147 else
4148 {
4149 // We don't own the image, dereference and replace with copy
4150 --_imgRef->_refCount;
4151 _imgRef = new ImageRef( image, constOptions() );
4152 }
4153 }
4154
4155 return _imgRef->_image;
4156}
4157
4158//
4159// Prepare to modify image or image options
4160// Replace current image and options with copy if reference count > 1
4161//
4162void Magick::Image::modifyImage( void )
4163{
4164 {
4165 Lock( &_imgRef->_mutexLock );
4166 if ( _imgRef->_refCount == 1 )
4167 {
4168 // De-register image and return
4169 _imgRef->id( -1 );
4170 return;
4171 }
4172 }
4173
4174 ExceptionInfo exceptionInfo;
4175 GetExceptionInfo( &exceptionInfo );
4176 replaceImage( CloneImage( image(),
4177 0, // columns
4178 0, // rows
4179 MagickTrue, // orphan
4180 &exceptionInfo) );
4181 throwException( exceptionInfo );
4182 (void) DestroyExceptionInfo( &exceptionInfo );
4183 return;
4184}
4185
4186//
4187// Test for an ImageMagick reported error and throw exception if one
4188// has been reported. Secretly resets image->exception back to default
4189// state even though this method is const.
4190//
4191void Magick::Image::throwImageException( void ) const
4192{
4193 // Throw C++ exception while resetting Image exception to default state
4194 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4195}
4196
4197// Register image with image registry or obtain registration id
cristybb503372010-05-27 20:51:26 +00004198ssize_t Magick::Image::registerId( void )
cristy3ed852e2009-09-05 21:47:34 +00004199{
4200 Lock( &_imgRef->_mutexLock );
4201 if( _imgRef->id() < 0 )
4202 {
4203 char id[MaxTextExtent];
4204 ExceptionInfo exceptionInfo;
4205 GetExceptionInfo( &exceptionInfo );
4206 _imgRef->id(_imgRef->id()+1);
cristye8c25f92010-06-03 00:53:06 +00004207 sprintf(id,"%.20g\n",(double) _imgRef->id());
cristy3ed852e2009-09-05 21:47:34 +00004208 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4209 throwException( exceptionInfo );
4210 (void) DestroyExceptionInfo( &exceptionInfo );
4211 }
4212 return _imgRef->id();
4213}
4214
4215// Unregister image from image registry
4216void Magick::Image::unregisterId( void )
4217{
4218 modifyImage();
4219 _imgRef->id( -1 );
4220}
4221
4222//
4223// Create a local wrapper around MagickCoreTerminus
4224//
4225namespace Magick
4226{
4227 extern "C" {
4228 void MagickPlusPlusDestroyMagick(void);
4229 }
4230}
4231
4232void Magick::MagickPlusPlusDestroyMagick(void)
4233{
4234 if (magick_initialized)
4235 {
4236 magick_initialized=false;
4237 MagickCore::MagickCoreTerminus();
4238 }
4239}
4240
4241// C library initialization routine
4242void MagickDLLDecl Magick::InitializeMagick(const char *path_)
4243{
4244 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4245 if (!magick_initialized)
4246 magick_initialized=true;
4247}
4248
4249//
4250// Cleanup class to ensure that ImageMagick singletons are destroyed
4251// so as to avoid any resemblence to a memory leak (which seems to
4252// confuse users)
4253//
4254namespace Magick
4255{
4256
4257 class MagickCleanUp
4258 {
4259 public:
4260 MagickCleanUp( void );
4261 ~MagickCleanUp( void );
4262 };
4263
4264 // The destructor for this object is invoked when the destructors for
4265 // static objects in this translation unit are invoked.
4266 static MagickCleanUp magickCleanUpGuard;
4267}
4268
4269Magick::MagickCleanUp::MagickCleanUp ( void )
4270{
4271 // Don't even think about invoking InitializeMagick here!
4272}
4273
4274Magick::MagickCleanUp::~MagickCleanUp ( void )
4275{
4276 MagickPlusPlusDestroyMagick();
4277}