blob: 05a61bfcd393681e7e3004955ff168858adfdc5a [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 );
cristyed231572011-07-14 02:18:59 +0000348 PushPixelChannelMap( 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 );
cristyed231572011-07-14 02:18:59 +0000353 PopPixelChannelMap( 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 );
cristyed231572011-07-14 02:18:59 +0000498 PushPixelChannelMap( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +0000499 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +0000500 BlurImage( image(), radius_, sigma_, &exceptionInfo);
cristyed231572011-07-14 02:18:59 +0000501 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +0000502 replaceImage( newImage );
503 throwException( exceptionInfo );
504 (void) DestroyExceptionInfo( &exceptionInfo );
505}
506
507// Add border to image
508// Only uses width & height
509void Magick::Image::border( const Geometry &geometry_ )
510{
511 RectangleInfo borderInfo = geometry_;
512 ExceptionInfo exceptionInfo;
513 GetExceptionInfo( &exceptionInfo );
514 MagickCore::Image* newImage =
515 BorderImage( image(), &borderInfo, &exceptionInfo);
516 replaceImage( newImage );
517 throwException( exceptionInfo );
518 (void) DestroyExceptionInfo( &exceptionInfo );
519}
520
521// Extract channel from image
522void Magick::Image::channel ( const ChannelType channel_ )
523{
524 modifyImage();
cristyed231572011-07-14 02:18:59 +0000525 PushPixelChannelMap( image(), channel_ );
cristy3139dc22011-07-08 00:11:42 +0000526 SeparateImage ( image() );
cristyed231572011-07-14 02:18:59 +0000527 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +0000528 throwImageException();
529}
530
531// Set or obtain modulus channel depth
cristyfefab1b2011-07-05 00:33:22 +0000532void Magick::Image::channelDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +0000533{
534 modifyImage();
cristyfefab1b2011-07-05 00:33:22 +0000535 SetImageDepth( image(), depth_);
cristy3ed852e2009-09-05 21:47:34 +0000536 throwImageException();
537}
cristyfefab1b2011-07-05 00:33:22 +0000538size_t Magick::Image::channelDepth ( )
cristy3ed852e2009-09-05 21:47:34 +0000539{
cristyeaedf062010-05-29 22:36:02 +0000540 size_t channel_depth;
cristy3ed852e2009-09-05 21:47:34 +0000541
542 ExceptionInfo exceptionInfo;
543 GetExceptionInfo( &exceptionInfo );
cristyfefab1b2011-07-05 00:33:22 +0000544 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000545 throwException( exceptionInfo );
546 (void) DestroyExceptionInfo( &exceptionInfo );
547 return channel_depth;
548}
549
550
551// Charcoal-effect image
552void Magick::Image::charcoal( const double radius_, const double sigma_ )
553{
554 ExceptionInfo exceptionInfo;
555 GetExceptionInfo( &exceptionInfo );
556 MagickCore::Image* newImage =
557 CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
558 replaceImage( newImage );
559 throwException( exceptionInfo );
560 (void) DestroyExceptionInfo( &exceptionInfo );
561}
562
563// Chop image
564void Magick::Image::chop( const Geometry &geometry_ )
565{
566 RectangleInfo chopInfo = geometry_;
567 ExceptionInfo exceptionInfo;
568 GetExceptionInfo( &exceptionInfo );
569 MagickCore::Image* newImage =
570 ChopImage( image(), &chopInfo, &exceptionInfo);
571 replaceImage( newImage );
572 throwException( exceptionInfo );
573 (void) DestroyExceptionInfo( &exceptionInfo );
574}
575
cristyb32b90a2009-09-07 21:45:48 +0000576// contains one or more color corrections and applies the correction to the
577// image.
578void Magick::Image::cdl ( const std::string &cdl_ )
579{
580 modifyImage();
581 (void) ColorDecisionListImage( image(), cdl_.c_str() );
582 throwImageException();
583}
584
cristy3ed852e2009-09-05 21:47:34 +0000585// Colorize
cristy4c08aed2011-07-01 19:47:50 +0000586void Magick::Image::colorize ( const unsigned int alphaRed_,
587 const unsigned int alphaGreen_,
588 const unsigned int alphaBlue_,
cristy3ed852e2009-09-05 21:47:34 +0000589 const Color &penColor_ )
590{
591 if ( !penColor_.isValid() )
592 {
593 throwExceptionExplicit( OptionError,
594 "Pen color argument is invalid");
595 }
596
cristy4c08aed2011-07-01 19:47:50 +0000597 char alpha[MaxTextExtent];
598 FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
cristy3ed852e2009-09-05 21:47:34 +0000599
600 ExceptionInfo exceptionInfo;
601 GetExceptionInfo( &exceptionInfo );
602 MagickCore::Image* newImage =
cristy4c08aed2011-07-01 19:47:50 +0000603 ColorizeImage ( image(), alpha,
cristy3ed852e2009-09-05 21:47:34 +0000604 penColor_, &exceptionInfo );
605 replaceImage( newImage );
606 throwException( exceptionInfo );
607 (void) DestroyExceptionInfo( &exceptionInfo );
608}
cristy4c08aed2011-07-01 19:47:50 +0000609void Magick::Image::colorize ( const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000610 const Color &penColor_ )
611{
cristy4c08aed2011-07-01 19:47:50 +0000612 colorize( alpha_, alpha_, alpha_, penColor_ );
cristy3ed852e2009-09-05 21:47:34 +0000613}
614
cristy735e8942010-04-02 20:32:57 +0000615// Apply a color matrix to the image channels. The user supplied
616// matrix may be of order 1 to 6 (1x1 through 6x6).
cristyeaedf062010-05-29 22:36:02 +0000617void Magick::Image::colorMatrix (const size_t order_,
cristyc8918bb2010-04-03 01:57:27 +0000618 const double *color_matrix_)
cristy735e8942010-04-02 20:32:57 +0000619{
cristyc8918bb2010-04-03 01:57:27 +0000620 KernelInfo
621 *kernel_info;
622
cristy735e8942010-04-02 20:32:57 +0000623 ExceptionInfo exceptionInfo;
624 GetExceptionInfo( &exceptionInfo );
cristyc8918bb2010-04-03 01:57:27 +0000625 kernel_info=AcquireKernelInfo("1");
626 kernel_info->width=order_;
627 kernel_info->height=order_;
cristyc8918bb2010-04-03 01:57:27 +0000628 kernel_info->values=(double *) color_matrix_;
cristy735e8942010-04-02 20:32:57 +0000629 MagickCore::Image* newImage =
cristyc8918bb2010-04-03 01:57:27 +0000630 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
cristya2175d32010-04-03 02:25:17 +0000631 kernel_info->values=(double *) NULL;
cristyc8918bb2010-04-03 01:57:27 +0000632 kernel_info=DestroyKernelInfo(kernel_info);
cristy735e8942010-04-02 20:32:57 +0000633 replaceImage( newImage );
634 throwException( exceptionInfo );
635 (void) DestroyExceptionInfo( &exceptionInfo );
636}
637
cristy3ed852e2009-09-05 21:47:34 +0000638// Compare current image with another image
639// Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
640// in the current image. False is returned if the images are identical.
641bool Magick::Image::compare ( const Image &reference_ )
642{
643 modifyImage();
644 Image ref = reference_;
645 ref.modifyImage();
646 return static_cast<bool>(IsImagesEqual(image(), ref.image()));
647}
648
649// Composite two images
650void Magick::Image::composite ( const Image &compositeImage_,
cristyd99b0962010-05-29 23:14:26 +0000651 const ssize_t xOffset_,
652 const ssize_t yOffset_,
cristy3ed852e2009-09-05 21:47:34 +0000653 const CompositeOperator compose_ )
654{
655 // Image supplied as compositeImage is composited with current image and
656 // results in updating current image.
657 modifyImage();
658
659 CompositeImage( image(),
660 compose_,
661 compositeImage_.constImage(),
662 xOffset_,
663 yOffset_ );
664 throwImageException();
665}
666void Magick::Image::composite ( const Image &compositeImage_,
667 const Geometry &offset_,
668 const CompositeOperator compose_ )
669{
670 modifyImage();
671
cristybb503372010-05-27 20:51:26 +0000672 ssize_t x = offset_.xOff();
673 ssize_t y = offset_.yOff();
674 size_t width = columns();
675 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +0000676
677 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
678 &x, &y,
679 &width, &height );
680
681 CompositeImage( image(),
682 compose_,
683 compositeImage_.constImage(),
684 x, y );
685 throwImageException();
686}
687void Magick::Image::composite ( const Image &compositeImage_,
688 const GravityType gravity_,
689 const CompositeOperator compose_ )
690{
691 modifyImage();
692
693 RectangleInfo geometry;
694
695 SetGeometry(compositeImage_.constImage(), &geometry);
696 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
697
698 CompositeImage( image(),
699 compose_,
700 compositeImage_.constImage(),
701 geometry.x, geometry.y );
702 throwImageException();
703}
704
705// Contrast image
cristyeaedf062010-05-29 22:36:02 +0000706void Magick::Image::contrast ( const size_t sharpen_ )
cristy3ed852e2009-09-05 21:47:34 +0000707{
708 modifyImage();
709 ContrastImage ( image(), (MagickBooleanType) sharpen_ );
710 throwImageException();
711}
712
713// Convolve image. Applies a general image convolution kernel to the image.
714// order_ represents the number of columns and rows in the filter kernel.
715// kernel_ is an array of doubles representing the convolution kernel.
cristyeaedf062010-05-29 22:36:02 +0000716void Magick::Image::convolve ( const size_t order_,
cristy3ed852e2009-09-05 21:47:34 +0000717 const double *kernel_ )
718{
719 ExceptionInfo exceptionInfo;
720 GetExceptionInfo( &exceptionInfo );
721 MagickCore::Image* newImage =
722 ConvolveImage ( image(), order_,
723 kernel_, &exceptionInfo );
724 replaceImage( newImage );
725 throwException( exceptionInfo );
726 (void) DestroyExceptionInfo( &exceptionInfo );
727}
728
729// Crop image
730void Magick::Image::crop ( const Geometry &geometry_ )
731{
732 RectangleInfo cropInfo = geometry_;
733 ExceptionInfo exceptionInfo;
734 GetExceptionInfo( &exceptionInfo );
735 MagickCore::Image* newImage =
736 CropImage( image(),
737 &cropInfo,
738 &exceptionInfo);
739 replaceImage( newImage );
740 throwException( exceptionInfo );
741 (void) DestroyExceptionInfo( &exceptionInfo );
742}
743
744// Cycle Color Map
cristyd99b0962010-05-29 23:14:26 +0000745void Magick::Image::cycleColormap ( const ssize_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +0000746{
747 modifyImage();
748 CycleColormapImage( image(), amount_ );
749 throwImageException();
750}
751
752// Despeckle
753void Magick::Image::despeckle ( void )
754{
755 ExceptionInfo exceptionInfo;
756 GetExceptionInfo( &exceptionInfo );
757 MagickCore::Image* newImage =
758 DespeckleImage( image(), &exceptionInfo );
759 replaceImage( newImage );
760 throwException( exceptionInfo );
761 (void) DestroyExceptionInfo( &exceptionInfo );
762}
763
764// Display image
765void Magick::Image::display( void )
766{
767 DisplayImages( imageInfo(), image() );
768}
769
770// Distort image. distorts an image using various distortion methods, by
771// mapping color lookups of the source image to a new destination image
772// usally of the same size as the source image, unless 'bestfit' is set to
773// true.
cristyb32b90a2009-09-07 21:45:48 +0000774void Magick::Image::distort ( const DistortImageMethod method_,
cristybb503372010-05-27 20:51:26 +0000775 const size_t number_arguments_,
cristyb32b90a2009-09-07 21:45:48 +0000776 const double *arguments_,
777 const bool bestfit_ )
cristy3ed852e2009-09-05 21:47:34 +0000778{
779 ExceptionInfo exceptionInfo;
780 GetExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +0000781 MagickCore::Image* newImage = DistortImage ( image(), method_,
782 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
783 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000784 replaceImage( newImage );
785 throwException( exceptionInfo );
786 (void) DestroyExceptionInfo( &exceptionInfo );
787}
788
789// Draw on image using single drawable
790void Magick::Image::draw ( const Magick::Drawable &drawable_ )
791{
792 modifyImage();
793
794 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
795
796 if(wand)
797 {
798 drawable_.operator()(wand);
799
800 if( constImage()->exception.severity == UndefinedException)
801 DrawRender(wand);
802
803 wand=DestroyDrawingWand(wand);
804 }
805
806 throwImageException();
807}
808
809// Draw on image using a drawable list
810void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
811{
812 modifyImage();
813
814 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
815
816 if(wand)
817 {
818 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
819 p != drawable_.end(); p++ )
820 {
821 p->operator()(wand);
822 if( constImage()->exception.severity != UndefinedException)
823 break;
824 }
825
826 if( constImage()->exception.severity == UndefinedException)
827 DrawRender(wand);
828
829 wand=DestroyDrawingWand(wand);
830 }
831
832 throwImageException();
833}
834
835// Hilight edges in image
836void Magick::Image::edge ( const double radius_ )
837{
838 ExceptionInfo exceptionInfo;
839 GetExceptionInfo( &exceptionInfo );
840 MagickCore::Image* newImage =
841 EdgeImage( image(), radius_, &exceptionInfo );
842 replaceImage( newImage );
843 throwException( exceptionInfo );
844 (void) DestroyExceptionInfo( &exceptionInfo );
845}
846
847// Emboss image (hilight edges)
848void Magick::Image::emboss ( const double radius_, const double sigma_ )
849{
850 ExceptionInfo exceptionInfo;
851 GetExceptionInfo( &exceptionInfo );
852 MagickCore::Image* newImage =
853 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
854 replaceImage( newImage );
855 throwException( exceptionInfo );
856 (void) DestroyExceptionInfo( &exceptionInfo );
857}
858
859// Enhance image (minimize noise)
860void Magick::Image::enhance ( void )
861{
862 ExceptionInfo exceptionInfo;
863 GetExceptionInfo( &exceptionInfo );
864 MagickCore::Image* newImage =
865 EnhanceImage( image(), &exceptionInfo );
866 replaceImage( newImage );
867 throwException( exceptionInfo );
868 (void) DestroyExceptionInfo( &exceptionInfo );
869}
870
871// Equalize image (histogram equalization)
872void Magick::Image::equalize ( void )
873{
874 modifyImage();
875 EqualizeImage( image() );
876 throwImageException();
877}
878
879// Erase image to current "background color"
880void Magick::Image::erase ( void )
881{
882 modifyImage();
883 SetImageBackgroundColor( image() );
884 throwImageException();
885}
886
887// Extends image as defined by the geometry.
888//
889void Magick::Image::extent ( const Geometry &geometry_ )
890{
891 RectangleInfo extentInfo = geometry_;
892 modifyImage();
cristy8bf9e292010-02-21 17:48:01 +0000893 ExceptionInfo exceptionInfo;
894 GetExceptionInfo( &exceptionInfo );
cristy1ee42c42010-05-12 12:52:50 +0000895 MagickCore::Image* newImage =
896 ExtentImage ( image(), &extentInfo, &exceptionInfo );
897 replaceImage( newImage );
cristy8bf9e292010-02-21 17:48:01 +0000898 throwException( exceptionInfo );
899 (void) DestroyExceptionInfo( &exceptionInfo );
900}
901void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
902{
903 backgroundColor ( backgroundColor_ );
904 extent ( geometry_ );
905}
cristyff024b42010-02-21 22:55:09 +0000906void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
cristy8bf9e292010-02-21 17:48:01 +0000907{
908 image()->gravity = gravity_;
909 extent ( geometry_ );
910}
911void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
912{
913 image()->gravity = gravity_;
914 backgroundColor ( backgroundColor_ );
915 extent ( geometry_ );
cristy3ed852e2009-09-05 21:47:34 +0000916}
917
918// Flip image (reflect each scanline in the vertical direction)
919void Magick::Image::flip ( void )
920{
921 ExceptionInfo exceptionInfo;
922 GetExceptionInfo( &exceptionInfo );
923 MagickCore::Image* newImage =
924 FlipImage( image(), &exceptionInfo );
925 replaceImage( newImage );
926 throwException( exceptionInfo );
927 (void) DestroyExceptionInfo( &exceptionInfo );
928}
929
930// Flood-fill color across pixels that match the color of the
931// target pixel and are neighbors of the target pixel.
932// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000933void Magick::Image::floodFillColor( const ssize_t x_,
934 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000935 const Magick::Color &fillColor_ )
936{
937 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
938}
939void Magick::Image::floodFillColor( const Geometry &point_,
940 const Magick::Color &fillColor_ )
941{
942 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
943}
944
945// Flood-fill color across pixels starting at target-pixel and
946// stopping at pixels matching specified border color.
947// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000948void Magick::Image::floodFillColor( const ssize_t x_,
949 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000950 const Magick::Color &fillColor_,
951 const Magick::Color &borderColor_ )
952{
953 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
954 borderColor_ );
955}
956void Magick::Image::floodFillColor( const Geometry &point_,
957 const Magick::Color &fillColor_,
958 const Magick::Color &borderColor_ )
959{
960 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
961 borderColor_ );
962}
963
964// Floodfill pixels matching color (within fuzz factor) of target
cristy4c08aed2011-07-01 19:47:50 +0000965// pixel(x,y) with replacement alpha value using method.
cristy35ef8242010-06-03 16:24:13 +0000966void Magick::Image::floodFillOpacity( const ssize_t x_,
967 const ssize_t y_,
cristy4c08aed2011-07-01 19:47:50 +0000968 const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000969 const PaintMethod method_ )
970{
971 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +0000972 PixelInfo target;
973 GetPixelInfo(image(),&target);
cristy3ed852e2009-09-05 21:47:34 +0000974 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
975 target.red=pixel.red;
976 target.green=pixel.green;
977 target.blue=pixel.blue;
cristy4c08aed2011-07-01 19:47:50 +0000978 target.alpha=alpha_;
cristy3ed852e2009-09-05 21:47:34 +0000979 FloodfillPaintImage ( image(),
cristy3ed852e2009-09-05 21:47:34 +0000980 options()->drawInfo(), // const DrawInfo *draw_info
981 &target,
cristybb503372010-05-27 20:51:26 +0000982 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +0000983 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
984 throwImageException();
985}
986
987// Flood-fill texture across pixels that match the color of the
988// target pixel and are neighbors of the target pixel.
989// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000990void Magick::Image::floodFillTexture( const ssize_t x_,
991 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000992 const Magick::Image &texture_ )
993{
994 modifyImage();
995
996 // Set drawing pattern
997 options()->fillPattern(texture_.constImage());
998
999 // Get pixel view
1000 Pixels pixels(*this);
1001 // Fill image
cristy4c08aed2011-07-01 19:47:50 +00001002 Quantum *p = pixels.get(x_, y_, 1, 1 );
1003 PixelInfo target;
1004 GetPixelInfo(constImage(),&target);
1005 target.red=GetPixelRed(constImage(),p);
1006 target.green=GetPixelGreen(constImage(),p);
1007 target.blue=GetPixelBlue(constImage(),p);
cristy3ed852e2009-09-05 21:47:34 +00001008 if (p)
1009 FloodfillPaintImage ( image(), // Image *image
cristy3ed852e2009-09-05 21:47:34 +00001010 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(),
cristy3ed852e2009-09-05 21:47:34 +00001044 options()->drawInfo(),
1045 &target,
cristybb503372010-05-27 20:51:26 +00001046 static_cast<ssize_t>(x_),
1047 static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +00001048 MagickTrue);
1049
1050 throwImageException();
1051}
1052void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1053 const Magick::Image &texture_,
1054 const Magick::Color &borderColor_ )
1055{
1056 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1057}
1058
1059// Flop image (reflect each scanline in the horizontal direction)
1060void Magick::Image::flop ( void )
1061{
1062 ExceptionInfo exceptionInfo;
1063 GetExceptionInfo( &exceptionInfo );
1064 MagickCore::Image* newImage =
1065 FlopImage( image(), &exceptionInfo );
1066 replaceImage( newImage );
1067 throwException( exceptionInfo );
1068 (void) DestroyExceptionInfo( &exceptionInfo );
1069}
1070
1071// Frame image
1072void Magick::Image::frame ( const Geometry &geometry_ )
1073{
1074 FrameInfo info;
1075
cristybb503372010-05-27 20:51:26 +00001076 info.x = static_cast<ssize_t>(geometry_.width());
1077 info.y = static_cast<ssize_t>(geometry_.height());
1078 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1079 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
cristy3ed852e2009-09-05 21:47:34 +00001080 info.outer_bevel = geometry_.xOff();
1081 info.inner_bevel = geometry_.yOff();
1082
1083 ExceptionInfo exceptionInfo;
1084 GetExceptionInfo( &exceptionInfo );
1085 MagickCore::Image* newImage =
1086 FrameImage( image(), &info, &exceptionInfo );
1087 replaceImage( newImage );
1088 throwException( exceptionInfo );
1089 (void) DestroyExceptionInfo( &exceptionInfo );
1090}
cristyeaedf062010-05-29 22:36:02 +00001091void Magick::Image::frame ( const size_t width_,
1092 const size_t height_,
cristyd99b0962010-05-29 23:14:26 +00001093 const ssize_t outerBevel_, const ssize_t innerBevel_ )
cristy3ed852e2009-09-05 21:47:34 +00001094{
1095 FrameInfo info;
cristybb503372010-05-27 20:51:26 +00001096 info.x = static_cast<ssize_t>(width_);
1097 info.y = static_cast<ssize_t>(height_);
1098 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1099 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1100 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1101 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
cristy3ed852e2009-09-05 21:47:34 +00001102
1103 ExceptionInfo exceptionInfo;
1104 GetExceptionInfo( &exceptionInfo );
1105 MagickCore::Image* newImage =
1106 FrameImage( image(), &info, &exceptionInfo );
1107 replaceImage( newImage );
1108 throwException( exceptionInfo );
1109 (void) DestroyExceptionInfo( &exceptionInfo );
1110}
1111
cristyc9550792009-11-13 20:05:42 +00001112// Fx image. Applies a mathematical expression to the image.
1113void Magick::Image::fx ( const std::string expression )
1114{
1115 ExceptionInfo exceptionInfo;
1116 GetExceptionInfo( &exceptionInfo );
1117 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001118 FxImage ( image(), expression.c_str(), &exceptionInfo );
cristyc9550792009-11-13 20:05:42 +00001119 replaceImage( newImage );
1120 throwException( exceptionInfo );
1121 (void) DestroyExceptionInfo( &exceptionInfo );
1122}
cristy3ed852e2009-09-05 21:47:34 +00001123void Magick::Image::fx ( const std::string expression,
1124 const Magick::ChannelType channel )
1125{
1126 ExceptionInfo exceptionInfo;
1127 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001128 PushPixelChannelMap( image(), channel );
cristy3ed852e2009-09-05 21:47:34 +00001129 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001130 FxImage ( image(), expression.c_str(), &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001131 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001132 replaceImage( newImage );
1133 throwException( exceptionInfo );
1134 (void) DestroyExceptionInfo( &exceptionInfo );
1135}
1136
1137// Gamma correct image
1138void Magick::Image::gamma ( const double gamma_ )
1139{
cristy3ed852e2009-09-05 21:47:34 +00001140 modifyImage();
cristy50fbc382011-07-07 02:19:17 +00001141 GammaImage ( image(), gamma_ );
cristy3ed852e2009-09-05 21:47:34 +00001142}
1143
1144void Magick::Image::gamma ( const double gammaRed_,
1145 const double gammaGreen_,
1146 const double gammaBlue_ )
1147{
1148 char gamma[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001149 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
cristy3ed852e2009-09-05 21:47:34 +00001150 gammaRed_, gammaGreen_, gammaBlue_);
1151
1152 modifyImage();
cristy50fbc382011-07-07 02:19:17 +00001153 GammaImage ( image(), atof(gamma) );
cristy3ed852e2009-09-05 21:47:34 +00001154 throwImageException();
1155}
1156
1157// Gaussian blur image
1158// The number of neighbor pixels to be included in the convolution
1159// mask is specified by 'width_'. The standard deviation of the
1160// gaussian bell curve is specified by 'sigma_'.
1161void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1162{
1163 ExceptionInfo exceptionInfo;
1164 GetExceptionInfo( &exceptionInfo );
1165 MagickCore::Image* newImage =
1166 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
1167 replaceImage( newImage );
1168 throwException( exceptionInfo );
1169 (void) DestroyExceptionInfo( &exceptionInfo );
1170}
1171
1172void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1173 const double width_,
1174 const double sigma_ )
1175{
1176 ExceptionInfo exceptionInfo;
1177 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001178 PushPixelChannelMap( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00001179 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +00001180 GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001181 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001182 replaceImage( newImage );
1183 throwException( exceptionInfo );
1184 (void) DestroyExceptionInfo( &exceptionInfo );
1185}
1186
cristyb32b90a2009-09-07 21:45:48 +00001187// Apply a color lookup table (Hald CLUT) to the image.
1188void Magick::Image::haldClut ( const Image &clutImage_ )
1189{
1190 modifyImage();
1191 (void) HaldClutImage( image(), clutImage_.constImage() );
1192 throwImageException();
1193}
1194
cristy3ed852e2009-09-05 21:47:34 +00001195// Implode image
1196void Magick::Image::implode ( const double factor_ )
1197{
1198 ExceptionInfo exceptionInfo;
1199 GetExceptionInfo( &exceptionInfo );
1200 MagickCore::Image* newImage =
1201 ImplodeImage( image(), factor_, &exceptionInfo );
1202 replaceImage( newImage );
1203 throwException( exceptionInfo );
1204 (void) DestroyExceptionInfo( &exceptionInfo );
1205}
1206
cristy529fcc22009-11-14 18:15:08 +00001207// implements the inverse discrete Fourier transform (IFT) of the image either
1208// as a magnitude / phase or real / imaginary image pair.
1209void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1210{
1211 ExceptionInfo exceptionInfo;
1212 GetExceptionInfo( &exceptionInfo );
1213 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1214 phase_.constImage(), MagickTrue, &exceptionInfo);
1215 replaceImage( newImage );
1216 throwException( exceptionInfo );
1217 (void) DestroyExceptionInfo( &exceptionInfo );
1218}
1219void Magick::Image::inverseFourierTransform ( const Image &phase_,
1220 const bool magnitude_ )
1221{
1222 ExceptionInfo exceptionInfo;
1223 GetExceptionInfo( &exceptionInfo );
1224 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1225 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1226 &exceptionInfo);
1227 replaceImage( newImage );
1228 throwException( exceptionInfo );
1229 (void) DestroyExceptionInfo( &exceptionInfo );
1230}
1231
cristy3ed852e2009-09-05 21:47:34 +00001232// Level image. Adjust the levels of the image by scaling the colors
1233// falling between specified white and black points to the full
1234// available quantum range. The parameters provided represent the
1235// black, mid (gamma), and white points. The black point specifies
1236// the darkest color in the image. Colors darker than the black point
1237// are set to zero. Mid point (gamma) specifies a gamma correction to
1238// apply to the image. White point specifies the lightest color in the
1239// image. Colors brighter than the white point are set to the maximum
1240// quantum value. The black and white point have the valid range 0 to
1241// QuantumRange while gamma has a useful range of 0 to ten.
1242void Magick::Image::level ( const double black_point,
1243 const double white_point,
1244 const double gamma )
1245{
1246 modifyImage();
cristyf89cb1d2011-07-07 01:24:37 +00001247 (void) LevelImage( image(), black_point, white_point, gamma );
cristy3ed852e2009-09-05 21:47:34 +00001248 throwImageException();
1249}
1250
1251// Magnify image by integral size
1252void Magick::Image::magnify ( void )
1253{
1254 ExceptionInfo exceptionInfo;
1255 GetExceptionInfo( &exceptionInfo );
1256 MagickCore::Image* newImage =
1257 MagnifyImage( image(), &exceptionInfo );
1258 replaceImage( newImage );
1259 throwException( exceptionInfo );
1260 (void) DestroyExceptionInfo( &exceptionInfo );
1261}
1262
1263// Remap image colors with closest color from reference image
1264void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1265{
1266 modifyImage();
1267 options()->quantizeDither( dither_ );
1268 RemapImage ( options()->quantizeInfo(), image(),
1269 mapImage_.constImage());
1270 throwImageException();
1271}
cristy4c08aed2011-07-01 19:47:50 +00001272// Floodfill designated area with replacement alpha value
cristy3ed852e2009-09-05 21:47:34 +00001273void Magick::Image::matteFloodfill ( const Color &target_ ,
cristy4c08aed2011-07-01 19:47:50 +00001274 const unsigned int alpha_,
cristyd99b0962010-05-29 23:14:26 +00001275 const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001276 const Magick::PaintMethod method_ )
1277{
1278 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001279 PixelInfo target;
1280 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001281 target.red=static_cast<PixelPacket>(target_).red;
1282 target.green=static_cast<PixelPacket>(target_).green;
1283 target.blue=static_cast<PixelPacket>(target_).blue;
cristy4c08aed2011-07-01 19:47:50 +00001284 target.alpha=alpha_;
cristyed231572011-07-14 02:18:59 +00001285 PushPixelChannelMap( image(), AlphaChannel );
cristyd42d9952011-07-08 14:21:50 +00001286 FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
1287 method_ == FloodfillMethod ? MagickFalse : MagickTrue);
cristyed231572011-07-14 02:18:59 +00001288 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001289 throwImageException();
1290}
1291
1292// Filter image by replacing each pixel component with the median
1293// color in a circular neighborhood
1294void Magick::Image::medianFilter ( const double radius_ )
1295{
1296 ExceptionInfo exceptionInfo;
1297 GetExceptionInfo( &exceptionInfo );
1298 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001299 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1300 radius_,&exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001301 replaceImage( newImage );
1302 throwException( exceptionInfo );
1303 (void) DestroyExceptionInfo( &exceptionInfo );
1304}
1305
1306// Reduce image by integral size
1307void Magick::Image::minify ( void )
1308{
1309 ExceptionInfo exceptionInfo;
1310 GetExceptionInfo( &exceptionInfo );
1311 MagickCore::Image* newImage =
1312 MinifyImage( image(), &exceptionInfo );
1313 replaceImage( newImage );
1314 throwException( exceptionInfo );
1315 (void) DestroyExceptionInfo( &exceptionInfo );
1316}
1317
1318// Modulate percent hue, saturation, and brightness of an image
1319void Magick::Image::modulate ( const double brightness_,
1320 const double saturation_,
1321 const double hue_ )
1322{
1323 char modulate[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001324 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
cristy3ed852e2009-09-05 21:47:34 +00001325 brightness_, saturation_, hue_);
1326
1327 modifyImage();
1328 ModulateImage( image(), modulate );
1329 throwImageException();
1330}
1331
1332// Motion blur image with specified blur factor
1333// The radius_ parameter specifies the radius of the Gaussian, in
1334// pixels, not counting the center pixel. The sigma_ parameter
1335// specifies the standard deviation of the Laplacian, in pixels.
1336// The angle_ parameter specifies the angle the object appears
1337// to be comming from (zero degrees is from the right).
1338void Magick::Image::motionBlur ( const double radius_,
1339 const double sigma_,
1340 const double angle_ )
1341{
1342 ExceptionInfo exceptionInfo;
1343 GetExceptionInfo( &exceptionInfo );
1344 MagickCore::Image* newImage =
1345 MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
1346 replaceImage( newImage );
1347 throwException( exceptionInfo );
1348 (void) DestroyExceptionInfo( &exceptionInfo );
1349}
1350
1351// Negate image. Set grayscale_ to true to effect grayscale values
1352// only
1353void Magick::Image::negate ( const bool grayscale_ )
1354{
1355 modifyImage();
1356 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse );
1357 throwImageException();
1358}
1359
1360// Normalize image
1361void Magick::Image::normalize ( void )
1362{
1363 modifyImage();
1364 NormalizeImage ( image() );
1365 throwImageException();
1366}
1367
1368// Oilpaint image
1369void Magick::Image::oilPaint ( const double radius_ )
1370{
1371 ExceptionInfo exceptionInfo;
1372 GetExceptionInfo( &exceptionInfo );
1373 MagickCore::Image* newImage =
1374 OilPaintImage( image(), radius_, &exceptionInfo );
1375 replaceImage( newImage );
1376 throwException( exceptionInfo );
1377 (void) DestroyExceptionInfo( &exceptionInfo );
1378}
1379
cristy4c08aed2011-07-01 19:47:50 +00001380// Set or attenuate the alpha channel. If the image pixels are
1381// opaque then they are set to the specified alpha value, otherwise
1382// they are blended with the supplied alpha value. The value of
1383// alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1384// OpaqueAlpha and TransparentAlpha are available to specify
cristy3ed852e2009-09-05 21:47:34 +00001385// completely opaque or completely transparent, respectively.
cristy4c08aed2011-07-01 19:47:50 +00001386void Magick::Image::alpha ( const unsigned int alpha_ )
cristy3ed852e2009-09-05 21:47:34 +00001387{
1388 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001389 SetImageOpacity( image(), alpha_ );
cristy3ed852e2009-09-05 21:47:34 +00001390}
1391
1392// Change the color of an opaque pixel to the pen color.
1393void Magick::Image::opaque ( const Color &opaqueColor_,
1394 const Color &penColor_ )
1395{
1396 if ( !opaqueColor_.isValid() )
1397 {
1398 throwExceptionExplicit( OptionError,
1399 "Opaque color argument is invalid" );
1400 }
1401 if ( !penColor_.isValid() )
1402 {
1403 throwExceptionExplicit( OptionError,
1404 "Pen color argument is invalid" );
1405 }
1406
1407 modifyImage();
1408 std::string opaqueColor = opaqueColor_;
1409 std::string penColor = penColor_;
1410
cristy4c08aed2011-07-01 19:47:50 +00001411 PixelInfo opaque;
1412 PixelInfo pen;
cristy3ed852e2009-09-05 21:47:34 +00001413 (void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque,&image()->exception);
1414 (void) QueryMagickColor(std::string(penColor_).c_str(),&pen,&image()->exception);
1415 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse );
1416 throwImageException();
1417}
1418
1419// Ping is similar to read except only enough of the image is read to
1420// determine the image columns, rows, and filesize. Access the
1421// columns(), rows(), and fileSize() attributes after invoking ping.
1422// The image data is not valid after calling ping.
1423void Magick::Image::ping ( const std::string &imageSpec_ )
1424{
1425 options()->fileName( imageSpec_ );
1426 ExceptionInfo exceptionInfo;
1427 GetExceptionInfo( &exceptionInfo );
1428 MagickCore::Image* image =
1429 PingImage( imageInfo(), &exceptionInfo );
1430 replaceImage( image );
1431 throwException( exceptionInfo );
1432 (void) DestroyExceptionInfo( &exceptionInfo );
1433}
1434
1435// Ping is similar to read except only enough of the image is read
1436// to determine the image columns, rows, and filesize. Access the
1437// columns(), rows(), and fileSize() attributes after invoking
1438// ping. The image data is not valid after calling ping.
1439void Magick::Image::ping ( const Blob& blob_ )
1440{
1441 ExceptionInfo exceptionInfo;
1442 GetExceptionInfo( &exceptionInfo );
1443 MagickCore::Image* image =
1444 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1445 replaceImage( image );
1446 throwException( exceptionInfo );
1447 (void) DestroyExceptionInfo( &exceptionInfo );
1448}
1449
1450// Execute a named process module using an argc/argv syntax similar to
1451// that accepted by a C 'main' routine. An exception is thrown if the
1452// requested process module doesn't exist, fails to load, or fails during
1453// execution.
cristyd99b0962010-05-29 23:14:26 +00001454void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
cristy3ed852e2009-09-05 21:47:34 +00001455{
1456 modifyImage();
1457
cristyeaedf062010-05-29 22:36:02 +00001458 size_t status =
cristy3ed852e2009-09-05 21:47:34 +00001459 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1460 &image()->exception );
1461
1462 if (status == false)
1463 throwException( image()->exception );
1464}
1465
1466// Quantize colors in image using current quantization settings
1467// Set measureError_ to true in order to measure quantization error
1468void Magick::Image::quantize ( const bool measureError_ )
1469{
1470 modifyImage();
1471
1472 if (measureError_)
1473 options()->quantizeInfo()->measure_error=MagickTrue;
1474 else
1475 options()->quantizeInfo()->measure_error=MagickFalse;
1476
1477 QuantizeImage( options()->quantizeInfo(), image() );
1478
1479 throwImageException();
1480}
1481
1482// Apply an arithmetic or bitwise operator to the image pixel quantums.
1483void Magick::Image::quantumOperator ( const ChannelType channel_,
1484 const MagickEvaluateOperator operator_,
1485 double rvalue_)
1486{
1487 ExceptionInfo exceptionInfo;
1488 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001489 PushPixelChannelMap( image(), channel_ );
cristyd42d9952011-07-08 14:21:50 +00001490 EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
cristyed231572011-07-14 02:18:59 +00001491 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001492 throwException( exceptionInfo );
1493 (void) DestroyExceptionInfo( &exceptionInfo );
1494}
1495
cristyd99b0962010-05-29 23:14:26 +00001496void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00001497 const size_t columns_,
1498 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00001499 const ChannelType channel_,
1500 const MagickEvaluateOperator operator_,
1501 const double rvalue_)
1502{
1503 ExceptionInfo exceptionInfo;
1504 GetExceptionInfo( &exceptionInfo );
1505 RectangleInfo geometry;
1506 geometry.width = columns_;
1507 geometry.height = rows_;
1508 geometry.x = x_;
1509 geometry.y = y_;
1510 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1511 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001512 PushPixelChannelMap( image(), channel_);
cristyd42d9952011-07-08 14:21:50 +00001513 EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001514 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001515 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1516 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1517 crop_image = DestroyImageList(crop_image);
1518 throwException( exceptionInfo );
1519 (void) DestroyExceptionInfo( &exceptionInfo );
1520}
1521
1522// Raise image (lighten or darken the edges of an image to give a 3-D
1523// raised or lowered effect)
1524void Magick::Image::raise ( const Geometry &geometry_ ,
1525 const bool raisedFlag_ )
1526{
1527 RectangleInfo raiseInfo = geometry_;
1528 modifyImage();
1529 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse );
1530 throwImageException();
1531}
1532
1533
1534// Random threshold image.
1535//
1536// Changes the value of individual pixels based on the intensity
1537// of each pixel compared to a random threshold. The result is a
1538// low-contrast, two color image. The thresholds_ argument is a
1539// geometry containing LOWxHIGH thresholds. If the string
1540// contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1541// 3, or 4 will be performed instead. If a channel_ argument is
1542// specified then only the specified channel is altered. This is
1543// a very fast alternative to 'quantize' based dithering.
1544void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1545{
1546 randomThresholdChannel(thresholds_,DefaultChannels);
1547}
1548void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1549 const ChannelType channel_ )
1550{
1551 ExceptionInfo exceptionInfo;
1552 GetExceptionInfo( &exceptionInfo );
1553 modifyImage();
cristyed231572011-07-14 02:18:59 +00001554 PushPixelChannelMap( image(), channel_);
cristyf4ad9df2011-07-08 16:49:03 +00001555 (void) RandomThresholdImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00001556 static_cast<std::string>(thresholds_).c_str(),
1557 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001558 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001559 throwImageException();
1560 (void) DestroyExceptionInfo( &exceptionInfo );
1561}
1562
1563// Read image into current object
1564void Magick::Image::read ( const std::string &imageSpec_ )
1565{
1566 options()->fileName( imageSpec_ );
1567
1568 ExceptionInfo exceptionInfo;
1569 GetExceptionInfo( &exceptionInfo );
1570 MagickCore::Image* image =
1571 ReadImage( imageInfo(), &exceptionInfo );
1572
1573 // Ensure that multiple image frames were not read.
1574 if ( image && image->next )
1575 {
1576 // Destroy any extra image frames
1577 MagickCore::Image* next = image->next;
1578 image->next = 0;
1579 next->previous = 0;
1580 DestroyImageList( next );
1581
1582 }
1583 replaceImage( image );
1584 throwException( exceptionInfo );
1585 if ( image )
1586 throwException( image->exception );
1587 (void) DestroyExceptionInfo( &exceptionInfo );
1588}
1589
1590// Read image of specified size into current object
1591void Magick::Image::read ( const Geometry &size_,
1592 const std::string &imageSpec_ )
1593{
1594 size( size_ );
1595 read( imageSpec_ );
1596}
1597
1598// Read image from in-memory BLOB
1599void Magick::Image::read ( const Blob &blob_ )
1600{
1601 ExceptionInfo exceptionInfo;
1602 GetExceptionInfo( &exceptionInfo );
1603 MagickCore::Image* image =
1604 BlobToImage( imageInfo(),
1605 static_cast<const void *>(blob_.data()),
1606 blob_.length(), &exceptionInfo );
1607 replaceImage( image );
1608 throwException( exceptionInfo );
1609 if ( image )
1610 throwException( image->exception );
1611 (void) DestroyExceptionInfo( &exceptionInfo );
1612}
1613
1614// Read image of specified size from in-memory BLOB
1615void Magick::Image::read ( const Blob &blob_,
1616 const Geometry &size_ )
1617{
1618 // Set image size
1619 size( size_ );
1620 // Read from Blob
1621 read( blob_ );
1622}
1623
1624// Read image of specified size and depth from in-memory BLOB
1625void Magick::Image::read ( const Blob &blob_,
1626 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001627 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00001628{
1629 // Set image size
1630 size( size_ );
1631 // Set image depth
1632 depth( depth_ );
1633 // Read from Blob
1634 read( blob_ );
1635}
1636
1637// Read image of specified size, depth, and format from in-memory BLOB
1638void Magick::Image::read ( const Blob &blob_,
1639 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001640 const size_t depth_,
cristy3ed852e2009-09-05 21:47:34 +00001641 const std::string &magick_ )
1642{
1643 // Set image size
1644 size( size_ );
1645 // Set image depth
1646 depth( depth_ );
1647 // Set image magick
1648 magick( magick_ );
1649 // Set explicit image format
1650 fileName( magick_ + ':');
1651 // Read from Blob
1652 read( blob_ );
1653}
1654
1655// Read image of specified size, and format from in-memory BLOB
1656void Magick::Image::read ( const Blob &blob_,
1657 const Geometry &size_,
1658 const std::string &magick_ )
1659{
1660 // Set image size
1661 size( size_ );
1662 // Set image magick
1663 magick( magick_ );
1664 // Set explicit image format
1665 fileName( magick_ + ':');
1666 // Read from Blob
1667 read( blob_ );
1668}
1669
1670// Read image based on raw pixels in memory (ConstituteImage)
cristyeaedf062010-05-29 22:36:02 +00001671void Magick::Image::read ( const size_t width_,
1672 const size_t height_,
cristy3ed852e2009-09-05 21:47:34 +00001673 const std::string &map_,
1674 const StorageType type_,
1675 const void *pixels_ )
1676{
1677 ExceptionInfo exceptionInfo;
1678 GetExceptionInfo( &exceptionInfo );
1679 MagickCore::Image* image =
1680 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1681 &exceptionInfo );
1682 replaceImage( image );
1683 throwException( exceptionInfo );
1684 if ( image )
1685 throwException( image->exception );
1686 (void) DestroyExceptionInfo( &exceptionInfo );
1687}
1688
cristy3ed852e2009-09-05 21:47:34 +00001689// Reduce noise in image
1690void Magick::Image::reduceNoise ( const double order_ )
1691{
1692 ExceptionInfo exceptionInfo;
1693 GetExceptionInfo( &exceptionInfo );
1694 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001695 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1696 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001697 replaceImage( newImage );
1698 throwException( exceptionInfo );
1699 (void) DestroyExceptionInfo( &exceptionInfo );
1700}
1701
1702// Resize image
1703void Magick::Image::resize( const Geometry &geometry_ )
1704{
1705 // Calculate new size. This code should be supported using binary arguments
1706 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00001707 ssize_t x = 0;
1708 ssize_t y = 0;
1709 size_t width = columns();
1710 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001711
1712 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1713 &x, &y,
1714 &width, &height );
1715
1716 ExceptionInfo exceptionInfo;
1717 GetExceptionInfo( &exceptionInfo );
1718 MagickCore::Image* newImage =
1719 ResizeImage( image(),
1720 width,
1721 height,
1722 image()->filter,
1723 1.0,
1724 &exceptionInfo);
1725 replaceImage( newImage );
1726 throwException( exceptionInfo );
1727 (void) DestroyExceptionInfo( &exceptionInfo );
1728}
1729
1730// Roll image
1731void Magick::Image::roll ( const Geometry &roll_ )
1732{
cristybb503372010-05-27 20:51:26 +00001733 ssize_t xOff = roll_.xOff();
cristy3ed852e2009-09-05 21:47:34 +00001734 if ( roll_.xNegative() )
1735 xOff = 0 - xOff;
cristybb503372010-05-27 20:51:26 +00001736 ssize_t yOff = roll_.yOff();
cristy3ed852e2009-09-05 21:47:34 +00001737 if ( roll_.yNegative() )
1738 yOff = 0 - yOff;
1739
1740 ExceptionInfo exceptionInfo;
1741 GetExceptionInfo( &exceptionInfo );
1742 MagickCore::Image* newImage =
1743 RollImage( image(), xOff, yOff, &exceptionInfo );
1744 replaceImage( newImage );
1745 throwException( exceptionInfo );
1746 (void) DestroyExceptionInfo( &exceptionInfo );
1747}
cristyeaedf062010-05-29 22:36:02 +00001748void Magick::Image::roll ( const size_t columns_,
1749 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00001750{
1751 ExceptionInfo exceptionInfo;
1752 GetExceptionInfo( &exceptionInfo );
1753 MagickCore::Image* newImage =
1754 RollImage( image(),
cristybb503372010-05-27 20:51:26 +00001755 static_cast<ssize_t>(columns_),
1756 static_cast<ssize_t>(rows_), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001757 replaceImage( newImage );
1758 throwException( exceptionInfo );
1759 (void) DestroyExceptionInfo( &exceptionInfo );
1760}
1761
1762// Rotate image
1763void Magick::Image::rotate ( const double degrees_ )
1764{
1765 ExceptionInfo exceptionInfo;
1766 GetExceptionInfo( &exceptionInfo );
1767 MagickCore::Image* newImage =
1768 RotateImage( image(), degrees_, &exceptionInfo);
1769 replaceImage( newImage );
1770 throwException( exceptionInfo );
1771 (void) DestroyExceptionInfo( &exceptionInfo );
1772}
1773
1774// Sample image
1775void Magick::Image::sample ( const Geometry &geometry_ )
1776{
cristybb503372010-05-27 20:51:26 +00001777 ssize_t x = 0;
1778 ssize_t y = 0;
1779 size_t width = columns();
1780 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001781
1782 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1783 &x, &y,
1784 &width, &height );
1785
1786 ExceptionInfo exceptionInfo;
1787 GetExceptionInfo( &exceptionInfo );
1788 MagickCore::Image* newImage =
1789 SampleImage( image(), width, height, &exceptionInfo );
1790 replaceImage( newImage );
1791 throwException( exceptionInfo );
1792 (void) DestroyExceptionInfo( &exceptionInfo );
1793}
1794
1795// Scale image
1796void Magick::Image::scale ( const Geometry &geometry_ )
1797{
cristybb503372010-05-27 20:51:26 +00001798 ssize_t x = 0;
1799 ssize_t y = 0;
1800 size_t width = columns();
1801 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001802
1803 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1804 &x, &y,
1805 &width, &height );
1806
1807 ExceptionInfo exceptionInfo;
1808 GetExceptionInfo( &exceptionInfo );
1809 MagickCore::Image* newImage =
1810 ScaleImage( image(), width, height, &exceptionInfo );
1811 replaceImage( newImage );
1812 throwException( exceptionInfo );
1813 (void) DestroyExceptionInfo( &exceptionInfo );
1814}
1815
1816// Segment (coalesce similar image components) by analyzing the
1817// histograms of the color components and identifying units that are
1818// homogeneous with the fuzzy c-means technique.
1819void Magick::Image::segment ( const double clusterThreshold_,
1820 const double smoothingThreshold_ )
1821{
1822 modifyImage();
1823 SegmentImage ( image(),
1824 options()->quantizeColorSpace(),
1825 (MagickBooleanType) options()->verbose(),
1826 clusterThreshold_,
1827 smoothingThreshold_ );
1828 throwImageException();
1829 SyncImage( image() );
1830 throwImageException();
1831}
1832
1833// Shade image using distant light source
1834void Magick::Image::shade ( const double azimuth_,
1835 const double elevation_,
1836 const bool colorShading_ )
1837{
1838 ExceptionInfo exceptionInfo;
1839 GetExceptionInfo( &exceptionInfo );
1840 MagickCore::Image* newImage =
1841 ShadeImage( image(),
1842 colorShading_ == true ? MagickTrue : MagickFalse,
1843 azimuth_,
1844 elevation_,
1845 &exceptionInfo);
1846 replaceImage( newImage );
1847 throwException( exceptionInfo );
1848 (void) DestroyExceptionInfo( &exceptionInfo );
1849}
1850
1851// Sharpen pixels in image
1852void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1853{
1854 ExceptionInfo exceptionInfo;
1855 GetExceptionInfo( &exceptionInfo );
1856 MagickCore::Image* newImage =
1857 SharpenImage( image(),
1858 radius_,
1859 sigma_,
1860 &exceptionInfo );
1861 replaceImage( newImage );
1862 throwException( exceptionInfo );
1863 (void) DestroyExceptionInfo( &exceptionInfo );
1864}
1865
1866void Magick::Image::sharpenChannel ( const ChannelType channel_,
1867 const double radius_, const double sigma_ )
1868{
1869 ExceptionInfo exceptionInfo;
1870 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001871 PushPixelChannelMap( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00001872 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +00001873 SharpenImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00001874 radius_,
1875 sigma_,
1876 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001877 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001878 replaceImage( newImage );
1879 throwException( exceptionInfo );
1880 (void) DestroyExceptionInfo( &exceptionInfo );
1881}
1882
1883// Shave pixels from image edges.
1884void Magick::Image::shave ( const Geometry &geometry_ )
1885{
1886 RectangleInfo shaveInfo = geometry_;
1887 ExceptionInfo exceptionInfo;
1888 GetExceptionInfo( &exceptionInfo );
1889 MagickCore::Image* newImage =
1890 ShaveImage( image(),
1891 &shaveInfo,
1892 &exceptionInfo);
1893 replaceImage( newImage );
1894 throwException( exceptionInfo );
1895 (void) DestroyExceptionInfo( &exceptionInfo );
1896}
1897
1898// Shear image
1899void Magick::Image::shear ( const double xShearAngle_,
1900 const double yShearAngle_ )
1901{
1902 ExceptionInfo exceptionInfo;
1903 GetExceptionInfo( &exceptionInfo );
1904 MagickCore::Image* newImage =
1905 ShearImage( image(),
1906 xShearAngle_,
1907 yShearAngle_,
1908 &exceptionInfo );
1909 replaceImage( newImage );
1910 throwException( exceptionInfo );
1911 (void) DestroyExceptionInfo( &exceptionInfo );
1912}
1913
1914// Contrast image
cristyeaedf062010-05-29 22:36:02 +00001915void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
cristy3ed852e2009-09-05 21:47:34 +00001916{
1917 modifyImage();
cristy9ee60942011-07-06 14:54:38 +00001918 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint );
cristy3ed852e2009-09-05 21:47:34 +00001919 throwImageException();
1920}
1921
1922// Solarize image (similar to effect seen when exposing a photographic
1923// film to light during the development process)
1924void Magick::Image::solarize ( const double factor_ )
1925{
1926 modifyImage();
1927 SolarizeImage ( image(), factor_ );
1928 throwImageException();
1929}
1930
1931// Sparse color image, given a set of coordinates, interpolates the colors
1932// found at those coordinates, across the whole image, using various methods.
1933//
1934void Magick::Image::sparseColor ( const ChannelType channel,
1935 const SparseColorMethod method,
cristybb503372010-05-27 20:51:26 +00001936 const size_t number_arguments,
cristy3ed852e2009-09-05 21:47:34 +00001937 const double *arguments )
1938{
1939 ExceptionInfo exceptionInfo;
1940 GetExceptionInfo( &exceptionInfo );
cristy3884f692011-07-08 18:00:18 +00001941
cristyed231572011-07-14 02:18:59 +00001942 PushPixelChannelMap( image(), channel );
cristy3884f692011-07-08 18:00:18 +00001943 MagickCore::Image* newImage = SparseColorImage ( image(), method,
cristy3ed852e2009-09-05 21:47:34 +00001944 number_arguments, arguments, &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00001945 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00001946 replaceImage( newImage );
1947 throwException( exceptionInfo );
1948 (void) DestroyExceptionInfo( &exceptionInfo );
1949}
1950
1951// Spread pixels randomly within image by specified ammount
cristyeaedf062010-05-29 22:36:02 +00001952void Magick::Image::spread ( const size_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +00001953{
1954 ExceptionInfo exceptionInfo;
1955 GetExceptionInfo( &exceptionInfo );
1956 MagickCore::Image* newImage =
1957 SpreadImage( image(),
1958 amount_,
1959 &exceptionInfo );
1960 replaceImage( newImage );
1961 throwException( exceptionInfo );
1962 (void) DestroyExceptionInfo( &exceptionInfo );
1963}
1964
1965// Add a digital watermark to the image (based on second image)
1966void Magick::Image::stegano ( const Image &watermark_ )
1967{
1968 ExceptionInfo exceptionInfo;
1969 GetExceptionInfo( &exceptionInfo );
1970 MagickCore::Image* newImage =
1971 SteganoImage( image(),
1972 watermark_.constImage(),
1973 &exceptionInfo);
1974 replaceImage( newImage );
1975 throwException( exceptionInfo );
1976 (void) DestroyExceptionInfo( &exceptionInfo );
1977}
1978
1979// Stereo image (left image is current image)
1980void Magick::Image::stereo ( const Image &rightImage_ )
1981{
1982 ExceptionInfo exceptionInfo;
1983 GetExceptionInfo( &exceptionInfo );
1984 MagickCore::Image* newImage =
1985 StereoImage( image(),
1986 rightImage_.constImage(),
1987 &exceptionInfo);
1988 replaceImage( newImage );
1989 throwException( exceptionInfo );
1990 (void) DestroyExceptionInfo( &exceptionInfo );
1991}
1992
1993// Swirl image
1994void Magick::Image::swirl ( const double degrees_ )
1995{
1996 ExceptionInfo exceptionInfo;
1997 GetExceptionInfo( &exceptionInfo );
1998 MagickCore::Image* newImage =
1999 SwirlImage( image(), degrees_,
2000 &exceptionInfo);
2001 replaceImage( newImage );
2002 throwException( exceptionInfo );
2003 (void) DestroyExceptionInfo( &exceptionInfo );
2004}
2005
2006// Texture image
2007void Magick::Image::texture ( const Image &texture_ )
2008{
2009 modifyImage();
2010 TextureImage( image(), texture_.constImage() );
2011 throwImageException();
2012}
2013
2014// Threshold image
2015void Magick::Image::threshold ( const double threshold_ )
2016{
2017 modifyImage();
2018 BilevelImage( image(), threshold_ );
2019 throwImageException();
2020}
2021
2022// Transform image based on image geometry only
2023void Magick::Image::transform ( const Geometry &imageGeometry_ )
2024{
2025 modifyImage();
2026 TransformImage ( &(image()), 0,
2027 std::string(imageGeometry_).c_str() );
2028 throwImageException();
2029}
2030// Transform image based on image and crop geometries
2031void Magick::Image::transform ( const Geometry &imageGeometry_,
2032 const Geometry &cropGeometry_ )
2033{
2034 modifyImage();
2035 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2036 std::string(imageGeometry_).c_str() );
2037 throwImageException();
2038}
2039
2040// Add matte image to image, setting pixels matching color to transparent
2041void Magick::Image::transparent ( const Color &color_ )
2042{
2043 if ( !color_.isValid() )
2044 {
2045 throwExceptionExplicit( OptionError,
2046 "Color argument is invalid" );
2047 }
2048
2049 std::string color = color_;
2050
cristy4c08aed2011-07-01 19:47:50 +00002051 PixelInfo target;
cristy3ed852e2009-09-05 21:47:34 +00002052 (void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
2053 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00002054 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse );
cristy3ed852e2009-09-05 21:47:34 +00002055 throwImageException();
2056}
2057
2058// Add matte image to image, setting pixels matching color to transparent
2059void Magick::Image::transparentChroma(const Color &colorLow_,
2060 const Color &colorHigh_)
2061{
2062 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2063 {
2064 throwExceptionExplicit( OptionError,
2065 "Color argument is invalid" );
2066 }
2067
2068 std::string colorLow = colorLow_;
2069 std::string colorHigh = colorHigh_;
2070
cristy4c08aed2011-07-01 19:47:50 +00002071 PixelInfo targetLow;
2072 PixelInfo targetHigh;
cristy3ed852e2009-09-05 21:47:34 +00002073 (void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
2074 &image()->exception);
2075 (void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
2076 &image()->exception);
2077 modifyImage();
2078 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
cristy4c08aed2011-07-01 19:47:50 +00002079 TransparentAlpha, MagickFalse );
cristy3ed852e2009-09-05 21:47:34 +00002080 throwImageException();
2081}
2082
2083
2084// Trim edges that are the background color from the image
2085void Magick::Image::trim ( void )
2086{
2087 ExceptionInfo exceptionInfo;
2088 GetExceptionInfo( &exceptionInfo );
2089 MagickCore::Image* newImage =
2090 TrimImage( image(), &exceptionInfo);
2091 replaceImage( newImage );
2092 throwException( exceptionInfo );
2093 (void) DestroyExceptionInfo( &exceptionInfo );
2094}
2095
2096// Replace image with a sharpened version of the original image
2097// using the unsharp mask algorithm.
2098// radius_
2099// the radius of the Gaussian, in pixels, not counting the
2100// center pixel.
2101// sigma_
2102// the standard deviation of the Gaussian, in pixels.
2103// amount_
2104// the percentage of the difference between the original and
2105// the blur image that is added back into the original.
2106// threshold_
2107// the threshold in pixels needed to apply the diffence amount.
2108void Magick::Image::unsharpmask ( const double radius_,
2109 const double sigma_,
2110 const double amount_,
2111 const double threshold_ )
2112{
2113 ExceptionInfo exceptionInfo;
2114 GetExceptionInfo( &exceptionInfo );
2115 MagickCore::Image* newImage =
2116 UnsharpMaskImage( image(),
2117 radius_,
2118 sigma_,
2119 amount_,
2120 threshold_,
2121 &exceptionInfo );
2122 replaceImage( newImage );
2123 throwException( exceptionInfo );
2124 (void) DestroyExceptionInfo( &exceptionInfo );
2125}
2126
2127void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2128 const double radius_,
2129 const double sigma_,
2130 const double amount_,
2131 const double threshold_ )
2132{
2133 ExceptionInfo exceptionInfo;
2134 GetExceptionInfo( &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00002135 PushPixelChannelMap( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00002136 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +00002137 UnsharpMaskImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00002138 radius_,
2139 sigma_,
2140 amount_,
2141 threshold_,
2142 &exceptionInfo );
cristyed231572011-07-14 02:18:59 +00002143 PopPixelChannelMap( image() );
cristy3ed852e2009-09-05 21:47:34 +00002144 replaceImage( newImage );
2145 throwException( exceptionInfo );
2146 (void) DestroyExceptionInfo( &exceptionInfo );
2147}
2148
2149// Map image pixels to a sine wave
2150void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2151{
2152 ExceptionInfo exceptionInfo;
2153 GetExceptionInfo( &exceptionInfo );
2154 MagickCore::Image* newImage =
2155 WaveImage( image(),
2156 amplitude_,
2157 wavelength_,
2158 &exceptionInfo);
2159 replaceImage( newImage );
2160 throwException( exceptionInfo );
2161 (void) DestroyExceptionInfo( &exceptionInfo );
2162}
2163
2164// Write image to file
2165void Magick::Image::write( const std::string &imageSpec_ )
2166{
2167 modifyImage();
2168 fileName( imageSpec_ );
2169 WriteImage( imageInfo(), image() );
2170 throwImageException();
2171}
2172
2173// Write image to in-memory BLOB
2174void Magick::Image::write ( Blob *blob_ )
2175{
2176 modifyImage();
2177 size_t length = 2048; // Efficient size for small images
2178 ExceptionInfo exceptionInfo;
2179 GetExceptionInfo( &exceptionInfo );
2180 void* data = ImageToBlob( imageInfo(),
2181 image(),
2182 &length,
2183 &exceptionInfo);
2184 throwException( exceptionInfo );
2185 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2186 throwImageException();
2187 (void) DestroyExceptionInfo( &exceptionInfo );
2188}
2189void Magick::Image::write ( Blob *blob_,
2190 const std::string &magick_ )
2191{
2192 modifyImage();
2193 magick(magick_);
2194 size_t length = 2048; // Efficient size for small images
2195 ExceptionInfo exceptionInfo;
2196 GetExceptionInfo( &exceptionInfo );
2197 void* data = ImageToBlob( imageInfo(),
2198 image(),
2199 &length,
2200 &exceptionInfo);
2201 throwException( exceptionInfo );
2202 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2203 throwImageException();
2204 (void) DestroyExceptionInfo( &exceptionInfo );
2205}
2206void Magick::Image::write ( Blob *blob_,
2207 const std::string &magick_,
cristyeaedf062010-05-29 22:36:02 +00002208 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002209{
2210 modifyImage();
2211 magick(magick_);
2212 depth(depth_);
2213 size_t length = 2048; // Efficient size for small images
2214 ExceptionInfo exceptionInfo;
2215 GetExceptionInfo( &exceptionInfo );
2216 void* data = ImageToBlob( imageInfo(),
2217 image(),
2218 &length,
2219 &exceptionInfo);
2220 throwException( exceptionInfo );
2221 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2222 throwImageException();
2223 (void) DestroyExceptionInfo( &exceptionInfo );
2224}
2225
2226// Write image to an array of pixels with storage type specified
2227// by user (ExportImagePixels), e.g.
2228// image.write( 0, 0, 640, 1, "RGB", 0, pixels );
cristyd99b0962010-05-29 23:14:26 +00002229void Magick::Image::write ( const ssize_t x_,
2230 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00002231 const size_t columns_,
2232 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00002233 const std::string &map_,
2234 const StorageType type_,
2235 void *pixels_ )
2236{
2237 ExceptionInfo exceptionInfo;
2238 GetExceptionInfo( &exceptionInfo );
2239 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2240 pixels_,
2241 &exceptionInfo);
2242 throwException( exceptionInfo );
2243 (void) DestroyExceptionInfo( &exceptionInfo );
2244}
2245
2246// Zoom image
2247void Magick::Image::zoom( const Geometry &geometry_ )
2248{
2249 // Calculate new size. This code should be supported using binary arguments
2250 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00002251 ssize_t x = 0;
2252 ssize_t y = 0;
2253 size_t width = columns();
2254 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00002255
2256 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2257 &x, &y,
2258 &width, &height );
2259
2260 ExceptionInfo exceptionInfo;
2261 GetExceptionInfo( &exceptionInfo );
2262 MagickCore::Image* newImage =
cristy391f1ce2010-09-09 17:23:28 +00002263 ResizeImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00002264 width,
2265 height,
cristy391f1ce2010-09-09 17:23:28 +00002266 image()->filter,
2267 image()->blur,
cristy3ed852e2009-09-05 21:47:34 +00002268 &exceptionInfo);
2269 replaceImage( newImage );
2270 throwException( exceptionInfo );
2271 (void) DestroyExceptionInfo( &exceptionInfo );
2272}
2273
2274/*
2275 * Methods for setting image attributes
2276 *
2277 */
2278
2279// Join images into a single multi-image file
2280void Magick::Image::adjoin ( const bool flag_ )
2281{
2282 modifyImage();
2283 options()->adjoin( flag_ );
2284}
2285bool Magick::Image::adjoin ( void ) const
2286{
2287 return constOptions()->adjoin();
2288}
2289
2290// Remove pixel aliasing
2291void Magick::Image::antiAlias( const bool flag_ )
2292{
2293 modifyImage();
cristyeaedf062010-05-29 22:36:02 +00002294 options()->antiAlias( static_cast<size_t>(flag_) );
cristy3ed852e2009-09-05 21:47:34 +00002295}
2296bool Magick::Image::antiAlias( void )
2297{
2298 return static_cast<bool>( options()->antiAlias( ) );
2299}
2300
2301// Animation inter-frame delay
cristyeaedf062010-05-29 22:36:02 +00002302void Magick::Image::animationDelay ( const size_t delay_ )
cristy3ed852e2009-09-05 21:47:34 +00002303{
2304 modifyImage();
2305 image()->delay = delay_;
2306}
cristyeaedf062010-05-29 22:36:02 +00002307size_t Magick::Image::animationDelay ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002308{
2309 return constImage()->delay;
2310}
2311
2312// Number of iterations to play animation
cristyeaedf062010-05-29 22:36:02 +00002313void Magick::Image::animationIterations ( const size_t iterations_ )
cristy3ed852e2009-09-05 21:47:34 +00002314{
2315 modifyImage();
2316 image()->iterations = iterations_;
2317}
cristyeaedf062010-05-29 22:36:02 +00002318size_t Magick::Image::animationIterations ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002319{
2320 return constImage()->iterations;
2321}
2322
2323// Access/Update a named image attribute
2324void Magick::Image::attribute ( const std::string name_,
2325 const std::string value_ )
2326{
2327 modifyImage();
2328 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2329}
2330std::string Magick::Image::attribute ( const std::string name_ )
2331{
2332 const char *value = GetImageProperty( constImage(), name_.c_str() );
2333
2334 if ( value )
2335 return std::string( value );
2336
2337 return std::string(); // Intentionally no exception
2338}
2339
2340// Background color
cristy391f1ce2010-09-09 17:23:28 +00002341void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002342{
2343 modifyImage();
2344
cristy391f1ce2010-09-09 17:23:28 +00002345 if ( backgroundColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002346 {
cristy391f1ce2010-09-09 17:23:28 +00002347 image()->background_color = backgroundColor_;
cristy3ed852e2009-09-05 21:47:34 +00002348 }
2349 else
2350 {
cristy391f1ce2010-09-09 17:23:28 +00002351 image()->background_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002352 }
2353
cristy391f1ce2010-09-09 17:23:28 +00002354 options()->backgroundColor( backgroundColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002355}
2356Magick::Color Magick::Image::backgroundColor ( void ) const
2357{
2358 return constOptions()->backgroundColor( );
2359}
2360
2361// Background fill texture
2362void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2363{
2364 modifyImage();
2365 options()->backgroundTexture( backgroundTexture_ );
2366}
2367std::string Magick::Image::backgroundTexture ( void ) const
2368{
2369 return constOptions()->backgroundTexture( );
2370}
2371
2372// Original image columns
cristyeaedf062010-05-29 22:36:02 +00002373size_t Magick::Image::baseColumns ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002374{
2375 return constImage()->magick_columns;
2376}
2377
2378// Original image name
2379std::string Magick::Image::baseFilename ( void ) const
2380{
2381 return std::string(constImage()->magick_filename);
2382}
2383
2384// Original image rows
cristyeaedf062010-05-29 22:36:02 +00002385size_t Magick::Image::baseRows ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002386{
2387 return constImage()->magick_rows;
2388}
2389
2390// Border color
cristy391f1ce2010-09-09 17:23:28 +00002391void Magick::Image::borderColor ( const Color &borderColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002392{
2393 modifyImage();
2394
cristy391f1ce2010-09-09 17:23:28 +00002395 if ( borderColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002396 {
cristy391f1ce2010-09-09 17:23:28 +00002397 image()->border_color = borderColor_;
cristy3ed852e2009-09-05 21:47:34 +00002398 }
2399 else
2400 {
cristy391f1ce2010-09-09 17:23:28 +00002401 image()->border_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002402 }
2403
cristy391f1ce2010-09-09 17:23:28 +00002404 options()->borderColor( borderColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002405}
2406Magick::Color Magick::Image::borderColor ( void ) const
2407{
2408 return constOptions()->borderColor( );
2409}
2410
2411// Return smallest bounding box enclosing non-border pixels. The
2412// current fuzz value is used when discriminating between pixels.
2413// This is the crop bounding box used by crop(Geometry(0,0));
2414Magick::Geometry Magick::Image::boundingBox ( void ) const
2415{
2416 ExceptionInfo exceptionInfo;
2417 GetExceptionInfo( &exceptionInfo );
2418 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2419 throwException( exceptionInfo );
2420 (void) DestroyExceptionInfo( &exceptionInfo );
2421 return Geometry( bbox );
2422}
2423
2424// Text bounding-box base color
2425void Magick::Image::boxColor ( const Color &boxColor_ )
2426{
2427 modifyImage();
2428 options()->boxColor( boxColor_ );
2429}
2430Magick::Color Magick::Image::boxColor ( void ) const
2431{
2432 return constOptions()->boxColor( );
2433}
2434
2435// Pixel cache threshold. Once this threshold is exceeded, all
2436// subsequent pixels cache operations are to/from disk.
2437// This setting is shared by all Image objects.
2438/* static */
cristyeaedf062010-05-29 22:36:02 +00002439void Magick::Image::cacheThreshold ( const size_t threshold_ )
cristy3ed852e2009-09-05 21:47:34 +00002440{
2441 SetMagickResourceLimit( MemoryResource, threshold_ );
2442}
2443
2444void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2445{
2446 modifyImage();
2447 image()->chromaticity.blue_primary.x = x_;
2448 image()->chromaticity.blue_primary.y = y_;
2449}
2450void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2451{
2452 *x_ = constImage()->chromaticity.blue_primary.x;
2453 *y_ = constImage()->chromaticity.blue_primary.y;
2454}
2455
2456void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2457{
2458 modifyImage();
2459 image()->chromaticity.green_primary.x = x_;
2460 image()->chromaticity.green_primary.y = y_;
2461}
2462void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2463{
2464 *x_ = constImage()->chromaticity.green_primary.x;
2465 *y_ = constImage()->chromaticity.green_primary.y;
2466}
2467
2468void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2469{
2470 modifyImage();
2471 image()->chromaticity.red_primary.x = x_;
2472 image()->chromaticity.red_primary.y = y_;
2473}
2474void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2475{
2476 *x_ = constImage()->chromaticity.red_primary.x;
2477 *y_ = constImage()->chromaticity.red_primary.y;
2478}
2479
2480void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2481{
2482 modifyImage();
2483 image()->chromaticity.white_point.x = x_;
2484 image()->chromaticity.white_point.y = y_;
2485}
2486void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2487{
2488 *x_ = constImage()->chromaticity.white_point.x;
2489 *y_ = constImage()->chromaticity.white_point.y;
2490}
2491
2492// Set image storage class
2493void Magick::Image::classType ( const ClassType class_ )
2494{
2495 if ( classType() == PseudoClass && class_ == DirectClass )
2496 {
2497 // Use SyncImage to synchronize the DirectClass pixels with the
2498 // color map and then set to DirectClass type.
2499 modifyImage();
2500 SyncImage( image() );
2501 image()->colormap = (PixelPacket *)
2502 RelinquishMagickMemory( image()->colormap );
2503 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2504 return;
2505 }
2506
2507 if ( classType() == DirectClass && class_ == PseudoClass )
2508 {
2509 // Quantize to create PseudoClass color map
2510 modifyImage();
cristye6bbc092010-05-12 17:00:47 +00002511 quantizeColors(MaxColormapSize);
cristy3ed852e2009-09-05 21:47:34 +00002512 quantize();
2513 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2514 }
2515}
2516
2517// Associate a clip mask with the image. The clip mask must be the
2518// same dimensions as the image. Pass an invalid image to unset an
2519// existing clip mask.
2520void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2521{
2522 modifyImage();
2523
2524 if( clipMask_.isValid() )
2525 {
2526 // Set clip mask
2527 SetImageClipMask( image(), clipMask_.constImage() );
2528 }
2529 else
2530 {
2531 // Unset existing clip mask
2532 SetImageClipMask( image(), 0 );
2533 }
2534}
2535Magick::Image Magick::Image::clipMask ( void ) const
2536{
2537 ExceptionInfo exceptionInfo;
2538 GetExceptionInfo( &exceptionInfo );
2539 MagickCore::Image* image =
2540 GetImageClipMask( constImage(), &exceptionInfo );
2541 throwException( exceptionInfo );
2542 (void) DestroyExceptionInfo( &exceptionInfo );
2543 return Magick::Image( image );
2544}
2545
2546void Magick::Image::colorFuzz ( const double fuzz_ )
2547{
2548 modifyImage();
2549 image()->fuzz = fuzz_;
2550 options()->colorFuzz( fuzz_ );
2551}
2552double Magick::Image::colorFuzz ( void ) const
2553{
2554 return constOptions()->colorFuzz( );
2555}
2556
2557// Set color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002558void Magick::Image::colorMap ( const size_t index_,
cristy3ed852e2009-09-05 21:47:34 +00002559 const Color &color_ )
2560{
2561 MagickCore::Image* imageptr = image();
2562
2563 if (index_ > (MaxColormapSize-1) )
2564 throwExceptionExplicit( OptionError,
2565 "Colormap index must be less than MaxColormapSize" );
2566
2567 if ( !color_.isValid() )
2568 throwExceptionExplicit( OptionError,
2569 "Color argument is invalid");
2570 modifyImage();
2571
2572 // Ensure that colormap size is large enough
2573 if ( colorMapSize() < (index_+1) )
2574 colorMapSize( index_ + 1 );
2575
2576 // Set color at index in colormap
2577 (imageptr->colormap)[index_] = color_;
2578}
2579// Return color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002580Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
cristy3ed852e2009-09-05 21:47:34 +00002581{
2582 const MagickCore::Image* imageptr = constImage();
2583
2584 if ( !imageptr->colormap )
2585 throwExceptionExplicit( OptionError,
2586 "Image does not contain a colormap");
2587
2588 if ( index_ > imageptr->colors-1 )
2589 throwExceptionExplicit( OptionError,
2590 "Index out of range");
2591
2592 return Magick::Color( (imageptr->colormap)[index_] );
2593}
2594
2595// Colormap size (number of colormap entries)
cristyeaedf062010-05-29 22:36:02 +00002596void Magick::Image::colorMapSize ( const size_t entries_ )
cristy3ed852e2009-09-05 21:47:34 +00002597{
2598 if (entries_ >MaxColormapSize )
2599 throwExceptionExplicit( OptionError,
2600 "Colormap entries must not exceed MaxColormapSize" );
2601
2602 modifyImage();
2603
2604 MagickCore::Image* imageptr = image();
2605
2606 if( !imageptr->colormap )
2607 {
2608 // Allocate colormap
2609 imageptr->colormap =
2610 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2611 imageptr->colors = 0;
2612 }
2613 else if ( entries_ > imageptr->colors )
2614 {
2615 // Re-allocate colormap
2616 imageptr->colormap=(PixelPacket *)
2617 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2618 }
2619
2620 // Initialize any new colormap entries as all black
2621 Color black(0,0,0);
cristyeaedf062010-05-29 22:36:02 +00002622 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
cristy3ed852e2009-09-05 21:47:34 +00002623 (imageptr->colormap)[i] = black;
2624
2625 imageptr->colors = entries_;
2626}
cristyeaedf062010-05-29 22:36:02 +00002627size_t Magick::Image::colorMapSize ( void )
cristy3ed852e2009-09-05 21:47:34 +00002628{
2629 const MagickCore::Image* imageptr = constImage();
2630
2631 if ( !imageptr->colormap )
2632 throwExceptionExplicit( OptionError,
2633 "Image does not contain a colormap");
2634
2635 return imageptr->colors;
2636}
2637
2638// Image colorspace
2639void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2640{
2641 // Nothing to do?
2642 if ( image()->colorspace == colorSpace_ )
2643 return;
2644
2645 modifyImage();
2646
2647 if ( colorSpace_ != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002648 colorSpace_ != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002649 colorSpace_ != TransparentColorspace &&
2650 colorSpace_ != GRAYColorspace )
2651 {
2652 if (image()->colorspace != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002653 image()->colorspace != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002654 image()->colorspace != TransparentColorspace &&
2655 image()->colorspace != GRAYColorspace)
2656 {
2657 /* Transform to RGB colorspace as intermediate step */
2658 TransformRGBImage( image(), image()->colorspace );
2659 throwImageException();
2660 }
2661 /* Transform to final non-RGB colorspace */
2662 RGBTransformImage( image(), colorSpace_ );
2663 throwImageException();
2664 return;
2665 }
2666
2667 if ( colorSpace_ == RGBColorspace ||
cristy510d06a2011-07-06 23:43:54 +00002668 colorSpace_ == sRGBColorspace ||
cristy3ed852e2009-09-05 21:47:34 +00002669 colorSpace_ == TransparentColorspace ||
2670 colorSpace_ == GRAYColorspace )
2671 {
2672 /* Transform to a RGB-type colorspace */
2673 TransformRGBImage( image(), image()->colorspace );
2674 throwImageException();
2675 return;
2676 }
2677}
2678Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2679{
2680 return constImage()->colorspace;
2681}
2682
2683// Set image colorspace type.
2684void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2685{
2686 modifyImage();
2687 options()->colorspaceType( colorSpace_ );
2688}
2689Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2690{
2691 return constOptions()->colorspaceType();
2692}
2693
2694
2695// Comment string
2696void Magick::Image::comment ( const std::string &comment_ )
2697{
2698 modifyImage();
2699 SetImageProperty( image(), "Comment", NULL );
2700 if ( comment_.length() > 0 )
2701 SetImageProperty( image(), "Comment", comment_.c_str() );
2702 throwImageException();
2703}
2704std::string Magick::Image::comment ( void ) const
2705{
2706 const char *value = GetImageProperty( constImage(), "Comment" );
2707
2708 if ( value )
2709 return std::string( value );
2710
2711 return std::string(); // Intentionally no exception
2712}
2713
2714// Composition operator to be used when composition is implicitly used
2715// (such as for image flattening).
2716void Magick::Image::compose (const CompositeOperator compose_)
2717{
2718 image()->compose=compose_;
2719}
2720
2721Magick::CompositeOperator Magick::Image::compose ( void ) const
2722{
2723 return constImage()->compose;
2724}
2725
2726// Compression algorithm
2727void Magick::Image::compressType ( const CompressionType compressType_ )
2728{
2729 modifyImage();
2730 image()->compression = compressType_;
2731 options()->compressType( compressType_ );
2732}
2733Magick::CompressionType Magick::Image::compressType ( void ) const
2734{
2735 return constImage()->compression;
2736}
2737
2738// Enable printing of debug messages from ImageMagick
2739void Magick::Image::debug ( const bool flag_ )
2740{
2741 modifyImage();
2742 options()->debug( flag_ );
2743}
2744bool Magick::Image::debug ( void ) const
2745{
2746 return constOptions()->debug();
2747}
2748
2749// Tagged image format define (set/access coder-specific option) The
2750// magick_ option specifies the coder the define applies to. The key_
2751// option provides the key specific to that coder. The value_ option
2752// provides the value to set (if any). See the defineSet() method if the
2753// key must be removed entirely.
2754void Magick::Image::defineValue ( const std::string &magick_,
2755 const std::string &key_,
2756 const std::string &value_ )
2757{
2758 modifyImage();
2759 std::string format = magick_ + ":" + key_;
2760 std::string option = value_;
2761 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2762}
2763std::string Magick::Image::defineValue ( const std::string &magick_,
2764 const std::string &key_ ) const
2765{
2766 std::string definition = magick_ + ":" + key_;
2767 const char *option =
2768 GetImageOption ( constImageInfo(), definition.c_str() );
2769 if (option)
2770 return std::string( option );
2771 return std::string( );
2772}
2773
2774// Tagged image format define. Similar to the defineValue() method
2775// except that passing the flag_ value 'true' creates a value-less
2776// define with that format and key. Passing the flag_ value 'false'
2777// removes any existing matching definition. The method returns 'true'
2778// if a matching key exists, and 'false' if no matching key exists.
2779void Magick::Image::defineSet ( const std::string &magick_,
2780 const std::string &key_,
2781 bool flag_ )
2782{
2783 modifyImage();
2784 std::string definition = magick_ + ":" + key_;
2785 if (flag_)
2786 {
2787 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2788 }
2789 else
2790 {
2791 DeleteImageOption( imageInfo(), definition.c_str() );
2792 }
2793}
2794bool Magick::Image::defineSet ( const std::string &magick_,
2795 const std::string &key_ ) const
2796{
2797 std::string key = magick_ + ":" + key_;
2798 const char *option =
2799 GetImageOption ( constImageInfo(), key.c_str() );
2800 if (option)
2801 return true;
2802 return false;
2803}
2804
2805// Pixel resolution
2806void Magick::Image::density ( const Geometry &density_ )
2807{
2808 modifyImage();
2809 options()->density( density_ );
2810 if ( density_.isValid() )
2811 {
2812 image()->x_resolution = density_.width();
2813 if ( density_.height() != 0 )
2814 {
2815 image()->y_resolution = density_.height();
2816 }
2817 else
2818 {
2819 image()->y_resolution = density_.width();
2820 }
2821 }
2822 else
2823 {
2824 // Reset to default
2825 image()->x_resolution = 0;
2826 image()->y_resolution = 0;
2827 }
2828}
2829Magick::Geometry Magick::Image::density ( void ) const
2830{
2831 if (isValid())
2832 {
cristy35ef8242010-06-03 16:24:13 +00002833 ssize_t x_resolution=72;
2834 ssize_t y_resolution=72;
cristy3ed852e2009-09-05 21:47:34 +00002835
2836 if (constImage()->x_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002837 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002838
2839 if (constImage()->y_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002840 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002841
2842 return Geometry(x_resolution,y_resolution);
2843 }
2844
2845 return constOptions()->density( );
2846}
2847
2848// Image depth (bits allocated to red/green/blue components)
cristyeaedf062010-05-29 22:36:02 +00002849void Magick::Image::depth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002850{
cristyeaedf062010-05-29 22:36:02 +00002851 size_t depth = depth_;
cristy3ed852e2009-09-05 21:47:34 +00002852
2853 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2854 depth=MAGICKCORE_QUANTUM_DEPTH;
2855
2856 modifyImage();
2857 image()->depth=depth;
2858 options()->depth( depth );
2859}
cristyeaedf062010-05-29 22:36:02 +00002860size_t Magick::Image::depth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002861{
2862 return constImage()->depth;
2863}
2864
2865std::string Magick::Image::directory ( void ) const
2866{
2867 if ( constImage()->directory )
2868 return std::string( constImage()->directory );
2869
2870 throwExceptionExplicit( CorruptImageWarning,
2871 "Image does not contain a directory");
2872
2873 return std::string();
2874}
2875
2876// Endianness (little like Intel or big like SPARC) for image
2877// formats which support endian-specific options.
2878void Magick::Image::endian ( const Magick::EndianType endian_ )
2879{
2880 modifyImage();
2881 options()->endian( endian_ );
2882 image()->endian = endian_;
2883}
2884Magick::EndianType Magick::Image::endian ( void ) const
2885{
2886 return constImage()->endian;
2887}
2888
2889// EXIF profile (BLOB)
2890void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
2891{
2892 modifyImage();
2893 if ( exifProfile_.data() != 0 )
2894 {
2895 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
2896 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
2897 (void) SetImageProfile( image(), "exif", exif_profile);
2898 exif_profile =DestroyStringInfo( exif_profile );
2899 }
2900}
2901Magick::Blob Magick::Image::exifProfile( void ) const
2902{
2903 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
2904 if ( exif_profile == (StringInfo *) NULL)
2905 return Blob( 0, 0 );
2906 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
2907}
2908
2909// Image file name
2910void Magick::Image::fileName ( const std::string &fileName_ )
2911{
2912 modifyImage();
2913
2914 fileName_.copy( image()->filename,
2915 sizeof(image()->filename) - 1 );
2916 image()->filename[ fileName_.length() ] = 0; // Null terminate
2917
2918 options()->fileName( fileName_ );
2919
2920}
2921std::string Magick::Image::fileName ( void ) const
2922{
2923 return constOptions()->fileName( );
2924}
2925
2926// Image file size
2927off_t Magick::Image::fileSize ( void ) const
2928{
2929 return (off_t) GetBlobSize( constImage() );
2930}
2931
2932// Color to use when drawing inside an object
2933void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
2934{
2935 modifyImage();
2936 options()->fillColor(fillColor_);
2937}
2938Magick::Color Magick::Image::fillColor ( void ) const
2939{
2940 return constOptions()->fillColor();
2941}
2942
2943// Rule to use when filling drawn objects
2944void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
2945{
2946 modifyImage();
2947 options()->fillRule(fillRule_);
2948}
2949Magick::FillRule Magick::Image::fillRule ( void ) const
2950{
2951 return constOptions()->fillRule();
2952}
2953
2954// Pattern to use while filling drawn objects.
2955void Magick::Image::fillPattern ( const Image &fillPattern_ )
2956{
2957 modifyImage();
2958 if(fillPattern_.isValid())
2959 options()->fillPattern( fillPattern_.constImage() );
2960 else
2961 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
2962}
2963Magick::Image Magick::Image::fillPattern ( void ) const
2964{
2965 // FIXME: This is inordinately innefficient
2966 Image texture;
2967
2968 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
2969
2970 if ( tmpTexture )
2971 {
2972 ExceptionInfo exceptionInfo;
2973 GetExceptionInfo( &exceptionInfo );
2974 MagickCore::Image* image =
2975 CloneImage( tmpTexture,
2976 0, // columns
2977 0, // rows
2978 MagickTrue, // orphan
2979 &exceptionInfo);
2980 texture.replaceImage( image );
2981 throwException( exceptionInfo );
2982 (void) DestroyExceptionInfo( &exceptionInfo );
2983 }
2984 return texture;
2985}
2986
2987// Filter used by zoom
2988void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
2989{
2990 modifyImage();
2991 image()->filter = filterType_;
2992}
2993Magick::FilterTypes Magick::Image::filterType ( void ) const
2994{
2995 return constImage()->filter;
2996}
2997
2998// Font name
2999void Magick::Image::font ( const std::string &font_ )
3000{
3001 modifyImage();
3002 options()->font( font_ );
3003}
3004std::string Magick::Image::font ( void ) const
3005{
3006 return constOptions()->font( );
3007}
3008
3009// Font point size
3010void Magick::Image::fontPointsize ( const double pointSize_ )
3011{
3012 modifyImage();
3013 options()->fontPointsize( pointSize_ );
3014}
3015double Magick::Image::fontPointsize ( void ) const
3016{
3017 return constOptions()->fontPointsize( );
3018}
3019
3020// Font type metrics
3021void Magick::Image::fontTypeMetrics( const std::string &text_,
3022 TypeMetric *metrics )
3023{
3024 DrawInfo *drawInfo = options()->drawInfo();
3025 drawInfo->text = const_cast<char *>(text_.c_str());
3026 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
3027 drawInfo->text = 0;
3028}
3029
3030// Image format string
3031std::string Magick::Image::format ( void ) const
3032{
3033 ExceptionInfo exceptionInfo;
3034 GetExceptionInfo( &exceptionInfo );
3035 const MagickInfo * magick_info
3036 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3037 throwException( exceptionInfo );
3038 (void) DestroyExceptionInfo( &exceptionInfo );
3039
3040 if (( magick_info != 0 ) &&
3041 ( *magick_info->description != '\0' ))
3042 return std::string(magick_info->description);
3043
3044 throwExceptionExplicit( CorruptImageWarning,
3045 "Unrecognized image magick type" );
3046 return std::string();
3047}
3048
3049// Gamma adjustment
3050double Magick::Image::gamma ( void ) const
3051{
3052 return constImage()->gamma;
3053}
3054
3055Magick::Geometry Magick::Image::geometry ( void ) const
3056{
3057 if ( constImage()->geometry )
3058 {
3059 return Geometry(constImage()->geometry);
3060 }
3061
3062 throwExceptionExplicit( OptionWarning,
3063 "Image does not contain a geometry");
3064
3065 return Geometry();
3066}
3067
cristyeaedf062010-05-29 22:36:02 +00003068void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
cristy3ed852e2009-09-05 21:47:34 +00003069{
3070 modifyImage();
3071 image()->dispose = (DisposeType) disposeMethod_;
3072}
cristyeaedf062010-05-29 22:36:02 +00003073size_t Magick::Image::gifDisposeMethod ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003074{
3075 // FIXME: It would be better to return an enumeration
3076 return constImage()->dispose;
3077}
3078
3079// ICC ICM color profile (BLOB)
3080void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3081{
3082 profile("icm",colorProfile_);
3083}
3084Magick::Blob Magick::Image::iccColorProfile( void ) const
3085{
3086 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3087 if ( color_profile == (StringInfo *) NULL)
3088 return Blob( 0, 0 );
3089 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3090}
3091
3092void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3093{
3094 modifyImage();
3095 image()->interlace = interlace_;
3096 options()->interlaceType ( interlace_ );
3097}
3098Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3099{
3100 return constImage()->interlace;
3101}
3102
3103// IPTC profile (BLOB)
3104void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3105{
3106 modifyImage();
3107 if ( iptcProfile_.data() != 0 )
3108 {
3109 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3110 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3111 (void) SetImageProfile( image(), "iptc", iptc_profile);
3112 iptc_profile =DestroyStringInfo( iptc_profile );
3113 }
3114}
3115Magick::Blob Magick::Image::iptcProfile( void ) const
3116{
3117 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3118 if ( iptc_profile == (StringInfo *) NULL)
3119 return Blob( 0, 0 );
3120 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3121}
3122
3123// Does object contain valid image?
3124void Magick::Image::isValid ( const bool isValid_ )
3125{
3126 if ( !isValid_ )
3127 {
3128 delete _imgRef;
3129 _imgRef = new ImageRef;
3130 }
3131 else if ( !isValid() )
3132 {
3133 // Construct with single-pixel black image to make
3134 // image valid. This is an obvious hack.
3135 size( Geometry(1,1) );
3136 read( "xc:#000000" );
3137 }
3138}
3139
3140bool Magick::Image::isValid ( void ) const
3141{
3142 if ( rows() && columns() )
3143 return true;
3144
3145 return false;
3146}
3147
3148// Label image
3149void Magick::Image::label ( const std::string &label_ )
3150{
3151 modifyImage();
3152 SetImageProperty ( image(), "Label", NULL );
3153 if ( label_.length() > 0 )
3154 SetImageProperty ( image(), "Label", label_.c_str() );
3155 throwImageException();
3156}
3157std::string Magick::Image::label ( void ) const
3158{
3159 const char *value = GetImageProperty( constImage(), "Label" );
3160
3161 if ( value )
3162 return std::string( value );
3163
3164 return std::string();
3165}
3166
3167void Magick::Image::magick ( const std::string &magick_ )
3168{
3169 modifyImage();
3170
3171 magick_.copy( image()->magick,
3172 sizeof(image()->magick) - 1 );
3173 image()->magick[ magick_.length() ] = 0;
3174
3175 options()->magick( magick_ );
3176}
3177std::string Magick::Image::magick ( void ) const
3178{
3179 if ( *(constImage()->magick) != '\0' )
3180 return std::string(constImage()->magick);
3181
3182 return constOptions()->magick( );
3183}
3184
3185void Magick::Image::matte ( const bool matteFlag_ )
3186{
3187 modifyImage();
3188
3189 // If matte channel is requested, but image doesn't already have a
3190 // matte channel, then create an opaque matte channel. Likewise, if
3191 // the image already has a matte channel but a matte channel is not
3192 // desired, then set the matte channel to opaque.
3193 if ((matteFlag_ && !constImage()->matte) ||
3194 (constImage()->matte && !matteFlag_))
cristy4c08aed2011-07-01 19:47:50 +00003195 SetImageOpacity(image(),OpaqueAlpha);
cristy3ed852e2009-09-05 21:47:34 +00003196
3197 image()->matte = (MagickBooleanType) matteFlag_;
3198}
3199bool Magick::Image::matte ( void ) const
3200{
3201 if ( constImage()->matte )
3202 return true;
3203 else
3204 return false;
3205}
3206
3207void Magick::Image::matteColor ( const Color &matteColor_ )
3208{
3209 modifyImage();
3210
3211 if ( matteColor_.isValid() )
3212 {
cristy391f1ce2010-09-09 17:23:28 +00003213 image()->matte_color = matteColor_;
3214 options()->matteColor( matteColor_ );
cristy3ed852e2009-09-05 21:47:34 +00003215 }
3216 else
3217 {
3218 // Set to default matte color
3219 Color tmpColor( "#BDBDBD" );
cristy391f1ce2010-09-09 17:23:28 +00003220 image()->matte_color = tmpColor;
cristy3ed852e2009-09-05 21:47:34 +00003221 options()->matteColor( tmpColor );
3222 }
3223}
3224Magick::Color Magick::Image::matteColor ( void ) const
3225{
3226 return Color( constImage()->matte_color.red,
3227 constImage()->matte_color.green,
cristy391f1ce2010-09-09 17:23:28 +00003228 constImage()->matte_color.blue );
cristy3ed852e2009-09-05 21:47:34 +00003229}
3230
3231double Magick::Image::meanErrorPerPixel ( void ) const
3232{
3233 return(constImage()->error.mean_error_per_pixel);
3234}
3235
3236// Image modulus depth (minimum number of bits required to support
3237// red/green/blue components without loss of accuracy)
cristyeaedf062010-05-29 22:36:02 +00003238void Magick::Image::modulusDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00003239{
3240 modifyImage();
3241 SetImageDepth( image(), depth_ );
3242 options()->depth( depth_ );
3243}
cristyeaedf062010-05-29 22:36:02 +00003244size_t Magick::Image::modulusDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003245{
3246 ExceptionInfo exceptionInfo;
3247 GetExceptionInfo( &exceptionInfo );
cristyeaedf062010-05-29 22:36:02 +00003248 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003249 throwException( exceptionInfo );
3250 (void) DestroyExceptionInfo( &exceptionInfo );
3251 return depth;
3252}
3253
3254void Magick::Image::monochrome ( const bool monochromeFlag_ )
3255{
3256 modifyImage();
3257 options()->monochrome( monochromeFlag_ );
3258}
3259bool Magick::Image::monochrome ( void ) const
3260{
3261 return constOptions()->monochrome( );
3262}
3263
3264Magick::Geometry Magick::Image::montageGeometry ( void ) const
3265{
3266 if ( constImage()->montage )
3267 return Magick::Geometry(constImage()->montage);
3268
3269 throwExceptionExplicit( CorruptImageWarning,
3270 "Image does not contain a montage" );
3271
3272 return Magick::Geometry();
3273}
3274
3275double Magick::Image::normalizedMaxError ( void ) const
3276{
3277 return(constImage()->error.normalized_maximum_error);
3278}
3279
3280double Magick::Image::normalizedMeanError ( void ) const
3281{
3282 return constImage()->error.normalized_mean_error;
3283}
3284
3285// Image orientation
3286void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3287{
3288 modifyImage();
3289 image()->orientation = orientation_;
3290}
3291Magick::OrientationType Magick::Image::orientation ( void ) const
3292{
3293 return constImage()->orientation;
3294}
3295
3296void Magick::Image::penColor ( const Color &penColor_ )
3297{
3298 modifyImage();
3299 options()->fillColor(penColor_);
3300 options()->strokeColor(penColor_);
3301}
3302Magick::Color Magick::Image::penColor ( void ) const
3303{
3304 return constOptions()->fillColor();
3305}
3306
3307void Magick::Image::penTexture ( const Image &penTexture_ )
3308{
3309 modifyImage();
3310 if(penTexture_.isValid())
3311 options()->fillPattern( penTexture_.constImage() );
3312 else
3313 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3314}
3315
3316Magick::Image Magick::Image::penTexture ( void ) const
3317{
3318 // FIXME: This is inordinately innefficient
3319 Image texture;
3320
3321 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3322
3323 if ( tmpTexture )
3324 {
3325 ExceptionInfo exceptionInfo;
3326 GetExceptionInfo( &exceptionInfo );
3327 MagickCore::Image* image =
3328 CloneImage( tmpTexture,
3329 0, // columns
3330 0, // rows
3331 MagickTrue, // orphan
3332 &exceptionInfo);
3333 texture.replaceImage( image );
3334 throwException( exceptionInfo );
3335 (void) DestroyExceptionInfo( &exceptionInfo );
3336 }
3337 return texture;
3338}
3339
3340// Set the color of a pixel.
cristy35ef8242010-06-03 16:24:13 +00003341void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00003342 const Color &color_ )
3343{
3344 // Test arguments to ensure they are within the image.
cristy07fb9182010-06-06 23:37:14 +00003345 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
cristy3ed852e2009-09-05 21:47:34 +00003346 throwExceptionExplicit( OptionError,
3347 "Access outside of image boundary" );
3348
3349 modifyImage();
3350
3351 // Set image to DirectClass
3352 classType( DirectClass );
3353
3354 // Get pixel view
3355 Pixels pixels(*this);
3356 // Set pixel value
cristy4c08aed2011-07-01 19:47:50 +00003357 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3358 PixelPacket packet = color_;
3359 MagickCore::SetPixelPacket(constImage(),&packet,pixel);
cristy3ed852e2009-09-05 21:47:34 +00003360 // Tell ImageMagick that pixels have been updated
3361 pixels.sync();
3362
3363 return;
3364}
3365
3366// Get the color of a pixel
cristy35ef8242010-06-03 16:24:13 +00003367Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3368 const ssize_t y_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003369{
3370 ClassType storage_class;
3371 storage_class = classType();
3372 // DirectClass
cristy4c08aed2011-07-01 19:47:50 +00003373 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3374 if ( pixel )
cristy3ed852e2009-09-05 21:47:34 +00003375 {
cristy4c08aed2011-07-01 19:47:50 +00003376 PixelPacket packet;
3377 MagickCore::GetPixelPacket(constImage(),pixel,&packet);
3378 return Color( packet );
cristy3ed852e2009-09-05 21:47:34 +00003379 }
3380
3381 return Color(); // invalid
3382}
3383
3384// Preferred size and location of an image canvas.
3385void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3386{
3387 modifyImage();
3388 options()->page( pageSize_ );
3389 image()->page = pageSize_;
3390}
3391Magick::Geometry Magick::Image::page ( void ) const
3392{
3393 return Geometry( constImage()->page.width,
3394 constImage()->page.height,
3395 AbsoluteValue(constImage()->page.x),
3396 AbsoluteValue(constImage()->page.y),
3397 constImage()->page.x < 0 ? true : false,
3398 constImage()->page.y < 0 ? true : false);
3399}
3400
3401// Add a named profile to an image or remove a named profile by
3402// passing an empty Blob (use default Blob constructor).
3403// Valid names are:
3404// "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3405void Magick::Image::profile( const std::string name_,
3406 const Magick::Blob &profile_ )
3407{
3408 modifyImage();
cristyd99b0962010-05-29 23:14:26 +00003409 ssize_t result = ProfileImage( image(), name_.c_str(),
cristy3ed852e2009-09-05 21:47:34 +00003410 (unsigned char *)profile_.data(),
3411 profile_.length(), MagickTrue);
3412
3413 if( !result )
3414 throwImageException();
3415}
3416
3417// Retrieve a named profile from the image.
3418// Valid names are:
3419// "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3420// an existing generic profile name.
3421Magick::Blob Magick::Image::profile( const std::string name_ ) const
3422{
3423 const MagickCore::Image* image = constImage();
3424
3425 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3426
3427 if ( profile != (StringInfo *) NULL)
3428 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3429
3430 Blob blob;
3431 Image temp_image = *this;
3432 temp_image.write( &blob, name_ );
3433 return blob;
3434}
3435
cristyeaedf062010-05-29 22:36:02 +00003436void Magick::Image::quality ( const size_t quality_ )
cristy3ed852e2009-09-05 21:47:34 +00003437{
3438 modifyImage();
3439 image()->quality = quality_;
3440 options()->quality( quality_ );
3441}
cristyeaedf062010-05-29 22:36:02 +00003442size_t Magick::Image::quality ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003443{
3444 return constImage()->quality;
3445}
3446
cristyeaedf062010-05-29 22:36:02 +00003447void Magick::Image::quantizeColors ( const size_t colors_ )
cristy3ed852e2009-09-05 21:47:34 +00003448{
3449 modifyImage();
3450 options()->quantizeColors( colors_ );
3451}
cristyeaedf062010-05-29 22:36:02 +00003452size_t Magick::Image::quantizeColors ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003453{
3454 return constOptions()->quantizeColors( );
3455}
3456
3457void Magick::Image::quantizeColorSpace
3458 ( const Magick::ColorspaceType colorSpace_ )
3459{
3460 modifyImage();
3461 options()->quantizeColorSpace( colorSpace_ );
3462}
3463Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3464{
3465 return constOptions()->quantizeColorSpace( );
3466}
3467
3468void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3469{
3470 modifyImage();
3471 options()->quantizeDither( ditherFlag_ );
3472}
3473bool Magick::Image::quantizeDither ( void ) const
3474{
3475 return constOptions()->quantizeDither( );
3476}
3477
cristyeaedf062010-05-29 22:36:02 +00003478void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
cristy3ed852e2009-09-05 21:47:34 +00003479{
3480 modifyImage();
3481 options()->quantizeTreeDepth( treeDepth_ );
3482}
cristyeaedf062010-05-29 22:36:02 +00003483size_t Magick::Image::quantizeTreeDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003484{
3485 return constOptions()->quantizeTreeDepth( );
3486}
3487
3488void Magick::Image::renderingIntent
3489 ( const Magick::RenderingIntent renderingIntent_ )
3490{
3491 modifyImage();
3492 image()->rendering_intent = renderingIntent_;
3493}
3494Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3495{
3496 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3497}
3498
3499void Magick::Image::resolutionUnits
3500 ( const Magick::ResolutionType resolutionUnits_ )
3501{
3502 modifyImage();
3503 image()->units = resolutionUnits_;
3504 options()->resolutionUnits( resolutionUnits_ );
3505}
3506Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3507{
3508 return constOptions()->resolutionUnits( );
3509}
3510
cristyeaedf062010-05-29 22:36:02 +00003511void Magick::Image::scene ( const size_t scene_ )
cristy3ed852e2009-09-05 21:47:34 +00003512{
3513 modifyImage();
3514 image()->scene = scene_;
3515}
cristyeaedf062010-05-29 22:36:02 +00003516size_t Magick::Image::scene ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003517{
3518 return constImage()->scene;
3519}
3520
3521std::string Magick::Image::signature ( const bool force_ ) const
3522{
3523 Lock( &_imgRef->_mutexLock );
3524
3525 // Re-calculate image signature if necessary
3526 if ( force_ ||
3527 !GetImageProperty(constImage(), "Signature") ||
3528 constImage()->taint )
3529 {
3530 SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
3531 }
3532
3533 const char *property = GetImageProperty(constImage(), "Signature");
3534
3535 return std::string( property );
3536}
3537
3538void Magick::Image::size ( const Geometry &geometry_ )
3539{
3540 modifyImage();
3541 options()->size( geometry_ );
3542 image()->rows = geometry_.height();
3543 image()->columns = geometry_.width();
3544}
3545Magick::Geometry Magick::Image::size ( void ) const
3546{
3547 return Magick::Geometry( constImage()->columns, constImage()->rows );
3548}
3549
cristy8198a752009-09-28 23:59:24 +00003550// Splice image
3551void Magick::Image::splice( const Geometry &geometry_ )
3552{
3553 RectangleInfo spliceInfo = geometry_;
3554 ExceptionInfo exceptionInfo;
3555 GetExceptionInfo( &exceptionInfo );
3556 MagickCore::Image* newImage =
3557 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3558 replaceImage( newImage );
3559 throwException( exceptionInfo );
3560 (void) DestroyExceptionInfo( &exceptionInfo );
3561}
3562
cristy3ed852e2009-09-05 21:47:34 +00003563// Obtain image statistics. Statistics are normalized to the range of
3564// 0.0 to 1.0 and are output to the specified ImageStatistics
3565// structure.
cristyd42d9952011-07-08 14:21:50 +00003566void Magick::Image::statistics ( ImageStatistics *statistics )
cristy3ed852e2009-09-05 21:47:34 +00003567{
3568 double
3569 maximum,
3570 minimum;
3571
3572 ExceptionInfo exceptionInfo;
3573 GetExceptionInfo( &exceptionInfo );
cristyd42d9952011-07-08 14:21:50 +00003574
cristyed231572011-07-14 02:18:59 +00003575 PushPixelChannelMap( image(), RedChannel);
cristyd42d9952011-07-08 14:21:50 +00003576 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003577 statistics->red.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003578 statistics->red.maximum=maximum;
3579 (void) GetImageMean( image(),&statistics->red.mean,
3580 &statistics->red.standard_deviation,&exceptionInfo);
3581 (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
3582 &statistics->red.skewness,&exceptionInfo);
cristyed231572011-07-14 02:18:59 +00003583 PopPixelChannelMap( image() );
cristyd42d9952011-07-08 14:21:50 +00003584
cristyed231572011-07-14 02:18:59 +00003585 PushPixelChannelMap( image(), GreenChannel);
cristyd42d9952011-07-08 14:21:50 +00003586 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003587 statistics->green.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003588 statistics->green.maximum=maximum;
3589 (void) GetImageMean( image(),&statistics->green.mean,
3590 &statistics->green.standard_deviation,&exceptionInfo);
3591 (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
3592 &statistics->green.skewness,&exceptionInfo);
cristyed231572011-07-14 02:18:59 +00003593 PopPixelChannelMap( image() );
cristyd42d9952011-07-08 14:21:50 +00003594
cristyed231572011-07-14 02:18:59 +00003595 PushPixelChannelMap( image(), GreenChannel);
cristyd42d9952011-07-08 14:21:50 +00003596 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003597 statistics->blue.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003598 statistics->blue.maximum=maximum;
3599 (void) GetImageMean( image(),&statistics->blue.mean,
3600 &statistics->blue.standard_deviation,&exceptionInfo);
3601 (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
3602 &statistics->blue.skewness,&exceptionInfo);
cristyed231572011-07-14 02:18:59 +00003603 PopPixelChannelMap( image() );
cristyd42d9952011-07-08 14:21:50 +00003604
cristyed231572011-07-14 02:18:59 +00003605 PushPixelChannelMap( image(), AlphaChannel);
cristyd42d9952011-07-08 14:21:50 +00003606 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy4c08aed2011-07-01 19:47:50 +00003607 statistics->alpha.minimum=minimum;
3608 statistics->alpha.maximum=maximum;
cristyd42d9952011-07-08 14:21:50 +00003609 (void) GetImageMean( image(),&statistics->alpha.mean,
3610 &statistics->alpha.standard_deviation,&exceptionInfo);
3611 (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
3612 &statistics->alpha.skewness,&exceptionInfo);
cristyed231572011-07-14 02:18:59 +00003613 PopPixelChannelMap( image() );
cristyd42d9952011-07-08 14:21:50 +00003614
cristy3ed852e2009-09-05 21:47:34 +00003615 throwException( exceptionInfo );
3616 (void) DestroyExceptionInfo( &exceptionInfo );
3617}
3618
cristy9f89a3f2011-02-12 17:02:35 +00003619// Strip strips an image of all profiles and comments.
3620void Magick::Image::strip ( void )
3621{
3622 modifyImage();
3623 StripImage( image() );
3624 throwImageException();
3625}
3626
cristy3ed852e2009-09-05 21:47:34 +00003627// enabled/disable stroke anti-aliasing
3628void Magick::Image::strokeAntiAlias ( const bool flag_ )
3629{
3630 modifyImage();
3631 options()->strokeAntiAlias(flag_);
3632}
3633bool Magick::Image::strokeAntiAlias ( void ) const
3634{
3635 return constOptions()->strokeAntiAlias();
3636}
3637
3638// Color to use when drawing object outlines
3639void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3640{
3641 modifyImage();
3642 options()->strokeColor(strokeColor_);
3643}
3644Magick::Color Magick::Image::strokeColor ( void ) const
3645{
3646 return constOptions()->strokeColor();
3647}
3648
3649// dash pattern for drawing vector objects (default one)
3650void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3651{
3652 modifyImage();
3653 options()->strokeDashArray( strokeDashArray_ );
3654}
3655
3656const double* Magick::Image::strokeDashArray ( void ) const
3657{
3658 return constOptions()->strokeDashArray( );
3659}
3660
3661// dash offset for drawing vector objects (default one)
3662void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3663{
3664 modifyImage();
3665 options()->strokeDashOffset( strokeDashOffset_ );
3666}
3667
3668double Magick::Image::strokeDashOffset ( void ) const
3669{
3670 return constOptions()->strokeDashOffset( );
3671}
3672
3673// Specify the shape to be used at the end of open subpaths when they
3674// are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3675// and SquareCap.
3676void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3677{
3678 modifyImage();
3679 options()->strokeLineCap( lineCap_ );
3680}
3681Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3682{
3683 return constOptions()->strokeLineCap( );
3684}
3685
3686// Specify the shape to be used at the corners of paths (or other
3687// vector shapes) when they are stroked. Values of LineJoin are
3688// UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3689void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3690{
3691 modifyImage();
3692 options()->strokeLineJoin( lineJoin_ );
3693}
3694Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3695{
3696 return constOptions()->strokeLineJoin( );
3697}
3698
3699// Specify miter limit. When two line segments meet at a sharp angle
3700// and miter joins have been specified for 'lineJoin', it is possible
3701// for the miter to extend far beyond the thickness of the line
3702// stroking the path. The miterLimit' imposes a limit on the ratio of
3703// the miter length to the 'lineWidth'. The default value of this
3704// parameter is 4.
cristyeaedf062010-05-29 22:36:02 +00003705void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
cristy3ed852e2009-09-05 21:47:34 +00003706{
3707 modifyImage();
3708 options()->strokeMiterLimit( strokeMiterLimit_ );
3709}
cristyeaedf062010-05-29 22:36:02 +00003710size_t Magick::Image::strokeMiterLimit ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003711{
3712 return constOptions()->strokeMiterLimit( );
3713}
3714
3715// Pattern to use while stroking drawn objects.
3716void Magick::Image::strokePattern ( const Image &strokePattern_ )
3717{
3718 modifyImage();
3719 if(strokePattern_.isValid())
3720 options()->strokePattern( strokePattern_.constImage() );
3721 else
3722 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3723}
3724Magick::Image Magick::Image::strokePattern ( void ) const
3725{
3726 // FIXME: This is inordinately innefficient
3727 Image texture;
3728
3729 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3730
3731 if ( tmpTexture )
3732 {
3733 ExceptionInfo exceptionInfo;
3734 GetExceptionInfo( &exceptionInfo );
3735 MagickCore::Image* image =
3736 CloneImage( tmpTexture,
3737 0, // columns
3738 0, // rows
3739 MagickTrue, // orphan
3740 &exceptionInfo);
3741 throwException( exceptionInfo );
3742 (void) DestroyExceptionInfo( &exceptionInfo );
3743 texture.replaceImage( image );
3744 }
3745 return texture;
3746}
3747
3748// Stroke width for drawing lines, circles, ellipses, etc.
3749void Magick::Image::strokeWidth ( const double strokeWidth_ )
3750{
3751 modifyImage();
3752 options()->strokeWidth( strokeWidth_ );
3753}
3754double Magick::Image::strokeWidth ( void ) const
3755{
3756 return constOptions()->strokeWidth( );
3757}
3758
cristyeaedf062010-05-29 22:36:02 +00003759void Magick::Image::subImage ( const size_t subImage_ )
cristy3ed852e2009-09-05 21:47:34 +00003760{
3761 modifyImage();
3762 options()->subImage( subImage_ );
3763}
cristyeaedf062010-05-29 22:36:02 +00003764size_t Magick::Image::subImage ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003765{
3766 return constOptions()->subImage( );
3767}
3768
cristyeaedf062010-05-29 22:36:02 +00003769void Magick::Image::subRange ( const size_t subRange_ )
cristy3ed852e2009-09-05 21:47:34 +00003770{
3771 modifyImage();
3772 options()->subRange( subRange_ );
3773}
cristyeaedf062010-05-29 22:36:02 +00003774size_t Magick::Image::subRange ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003775{
3776 return constOptions()->subRange( );
3777}
3778
3779// Annotation text encoding (e.g. "UTF-16")
3780void Magick::Image::textEncoding ( const std::string &encoding_ )
3781{
3782 modifyImage();
3783 options()->textEncoding( encoding_ );
3784}
3785std::string Magick::Image::textEncoding ( void ) const
3786{
3787 return constOptions()->textEncoding( );
3788}
3789
cristybb503372010-05-27 20:51:26 +00003790size_t Magick::Image::totalColors ( void )
cristy3ed852e2009-09-05 21:47:34 +00003791{
3792 ExceptionInfo exceptionInfo;
3793 GetExceptionInfo( &exceptionInfo );
cristybb503372010-05-27 20:51:26 +00003794 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003795 throwException( exceptionInfo );
3796 (void) DestroyExceptionInfo( &exceptionInfo );
3797 return colors;
3798}
3799
3800// Origin of coordinate system to use when annotating with text or drawing
3801void Magick::Image::transformOrigin ( const double x_, const double y_ )
3802{
3803 modifyImage();
3804 options()->transformOrigin( x_, y_ );
3805}
3806
3807// Rotation to use when annotating with text or drawing
3808void Magick::Image::transformRotation ( const double angle_ )
3809{
3810 modifyImage();
3811 options()->transformRotation( angle_ );
3812}
3813
3814// Reset transformation parameters to default
3815void Magick::Image::transformReset ( void )
3816{
3817 modifyImage();
3818 options()->transformReset();
3819}
3820
3821// Scale to use when annotating with text or drawing
3822void Magick::Image::transformScale ( const double sx_, const double sy_ )
3823{
3824 modifyImage();
3825 options()->transformScale( sx_, sy_ );
3826}
3827
3828// Skew to use in X axis when annotating with text or drawing
3829void Magick::Image::transformSkewX ( const double skewx_ )
3830{
3831 modifyImage();
3832 options()->transformSkewX( skewx_ );
3833}
3834
3835// Skew to use in Y axis when annotating with text or drawing
3836void Magick::Image::transformSkewY ( const double skewy_ )
3837{
3838 modifyImage();
3839 options()->transformSkewY( skewy_ );
3840}
3841
3842// Image representation type
3843Magick::ImageType Magick::Image::type ( void ) const
3844{
3845
3846 ExceptionInfo exceptionInfo;
3847 GetExceptionInfo( &exceptionInfo );
3848 ImageType image_type = constOptions()->type();
3849 if ( image_type == UndefinedType )
3850 image_type= GetImageType( constImage(), &exceptionInfo);
3851 throwException( exceptionInfo );
3852 (void) DestroyExceptionInfo( &exceptionInfo );
3853 return image_type;
3854}
3855void Magick::Image::type ( const Magick::ImageType type_)
3856{
3857 modifyImage();
3858 options()->type( type_ );
3859 SetImageType( image(), type_ );
3860}
3861
3862void Magick::Image::verbose ( const bool verboseFlag_ )
3863{
3864 modifyImage();
3865 options()->verbose( verboseFlag_ );
3866}
3867bool Magick::Image::verbose ( void ) const
3868{
3869 return constOptions()->verbose( );
3870}
3871
3872void Magick::Image::view ( const std::string &view_ )
3873{
3874 modifyImage();
3875 options()->view( view_ );
3876}
3877std::string Magick::Image::view ( void ) const
3878{
3879 return constOptions()->view( );
3880}
3881
3882// Virtual pixel method
3883void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
3884{
3885 modifyImage();
3886 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
3887 options()->virtualPixelMethod( virtual_pixel_method_ );
3888}
3889Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
3890{
3891 return GetImageVirtualPixelMethod( constImage() );
3892}
3893
3894void Magick::Image::x11Display ( const std::string &display_ )
3895{
3896 modifyImage();
3897 options()->x11Display( display_ );
3898}
3899std::string Magick::Image::x11Display ( void ) const
3900{
3901 return constOptions()->x11Display( );
3902}
3903
3904double Magick::Image::xResolution ( void ) const
3905{
3906 return constImage()->x_resolution;
3907}
3908double Magick::Image::yResolution ( void ) const
3909{
3910 return constImage()->y_resolution;
3911}
3912
3913// Copy Constructor
3914Magick::Image::Image( const Image & image_ )
3915 : _imgRef(image_._imgRef)
3916{
3917 Lock( &_imgRef->_mutexLock );
3918
3919 // Increase reference count
3920 ++_imgRef->_refCount;
3921}
3922
3923// Assignment operator
3924Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
3925{
3926 if( this != &image_ )
3927 {
3928 {
3929 Lock( &image_._imgRef->_mutexLock );
3930 ++image_._imgRef->_refCount;
3931 }
3932
3933 bool doDelete = false;
3934 {
3935 Lock( &_imgRef->_mutexLock );
3936 if ( --_imgRef->_refCount == 0 )
3937 doDelete = true;
3938 }
3939
3940 if ( doDelete )
3941 {
3942 // Delete old image reference with associated image and options.
3943 delete _imgRef;
3944 _imgRef = 0;
3945 }
3946 // Use new image reference
3947 _imgRef = image_._imgRef;
3948 }
3949
3950 return *this;
3951}
3952
3953//////////////////////////////////////////////////////////////////////
3954//
3955// Low-level Pixel Access Routines
3956//
3957// Also see the Pixels class, which provides support for multiple
3958// cache views. The low-level pixel access routines in the Image
3959// class are provided in order to support backward compatability.
3960//
3961//////////////////////////////////////////////////////////////////////
3962
3963// Transfers read-only pixels from the image to the pixel cache as
3964// defined by the specified region
cristy4c08aed2011-07-01 19:47:50 +00003965const Magick::Quantum* Magick::Image::getConstPixels
cristyd99b0962010-05-29 23:14:26 +00003966 ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00003967 const size_t columns_,
3968 const size_t rows_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003969{
3970 ExceptionInfo exceptionInfo;
3971 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00003972 const Quantum* p = (*GetVirtualPixels)( constImage(),
cristy3ed852e2009-09-05 21:47:34 +00003973 x_, y_,
3974 columns_, rows_,
3975 &exceptionInfo );
3976 throwException( exceptionInfo );
3977 (void) DestroyExceptionInfo( &exceptionInfo );
3978 return p;
3979}
3980
cristy4c08aed2011-07-01 19:47:50 +00003981// Obtain read-only pixel associated pixels channels
3982const void* Magick::Image::getConstMetacontent ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003983{
cristy4c08aed2011-07-01 19:47:50 +00003984 const void* result = GetVirtualMetacontent( constImage() );
cristy3ed852e2009-09-05 21:47:34 +00003985
3986 if( !result )
3987 throwImageException();
3988
3989 return result;
3990}
3991
cristy4c08aed2011-07-01 19:47:50 +00003992// Obtain image pixel associated pixels channels
3993void* Magick::Image::getMetacontent ( void )
cristy3ed852e2009-09-05 21:47:34 +00003994{
cristy4c08aed2011-07-01 19:47:50 +00003995 void* result = GetAuthenticMetacontent( image() );
cristy3ed852e2009-09-05 21:47:34 +00003996
3997 if( !result )
3998 throwImageException();
3999
4000 return ( result );
4001}
4002
4003// Transfers pixels from the image to the pixel cache as defined
4004// by the specified region. Modified pixels may be subsequently
4005// transferred back to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00004006Magick::Quantum* Magick::Image::getPixels ( 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 = (*GetAuthenticPixels)( 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// Allocates a pixel cache region to store image pixels as defined
4023// by the region rectangle. This area is subsequently transferred
4024// from the pixel cache to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00004025Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00004026 const size_t columns_,
4027 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00004028{
4029 modifyImage();
4030 ExceptionInfo exceptionInfo;
4031 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00004032 Quantum* result = (*QueueAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00004033 x_, y_,
4034 columns_, rows_, &exceptionInfo );
4035 throwException( exceptionInfo );
4036 (void) DestroyExceptionInfo( &exceptionInfo );
4037
4038 return result;
4039}
4040
4041// Transfers the image cache pixels to the image.
4042void Magick::Image::syncPixels ( void )
4043{
4044 ExceptionInfo exceptionInfo;
4045 GetExceptionInfo( &exceptionInfo );
4046 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4047 throwException( exceptionInfo );
4048 (void) DestroyExceptionInfo( &exceptionInfo );
4049}
4050
4051// Transfers one or more pixel components from a buffer or file
4052// into the image pixel cache of an image.
4053// Used to support image decoders.
4054void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4055 const unsigned char *source_ )
4056{
4057 QuantumInfo
4058 *quantum_info;
4059
4060 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4061 ExceptionInfo exceptionInfo;
4062 GetExceptionInfo( &exceptionInfo );
4063 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4064 quantum_,source_, &exceptionInfo);
4065 throwException( exceptionInfo );
4066 (void) DestroyExceptionInfo( &exceptionInfo );
4067 quantum_info=DestroyQuantumInfo(quantum_info);
4068}
4069
4070// Transfers one or more pixel components from the image pixel
4071// cache to a buffer or file.
4072// Used to support image encoders.
4073void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4074 unsigned char *destination_ )
4075{
4076 QuantumInfo
4077 *quantum_info;
4078
4079 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4080 ExceptionInfo exceptionInfo;
4081 GetExceptionInfo( &exceptionInfo );
4082 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4083 quantum_,destination_, &exceptionInfo);
4084 quantum_info=DestroyQuantumInfo(quantum_info);
4085 throwException( exceptionInfo );
4086 (void) DestroyExceptionInfo( &exceptionInfo );
4087}
4088
4089/////////////////////////////////////////////////////////////////////
4090//
4091// No end-user methods beyond this point
4092//
4093/////////////////////////////////////////////////////////////////////
4094
4095
4096//
4097// Construct using existing image and default options
4098//
4099Magick::Image::Image ( MagickCore::Image* image_ )
4100 : _imgRef(new ImageRef( image_))
4101{
4102}
4103
4104// Get Magick::Options*
4105Magick::Options* Magick::Image::options( void )
4106{
4107 return _imgRef->options();
4108}
4109const Magick::Options* Magick::Image::constOptions( void ) const
4110{
4111 return _imgRef->options();
4112}
4113
4114// Get MagickCore::Image*
4115MagickCore::Image*& Magick::Image::image( void )
4116{
4117 return _imgRef->image();
4118}
4119const MagickCore::Image* Magick::Image::constImage( void ) const
4120{
4121 return _imgRef->image();
4122}
4123
4124// Get ImageInfo *
4125MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4126{
4127 return _imgRef->options()->imageInfo();
4128}
4129const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4130{
4131 return _imgRef->options()->imageInfo();
4132}
4133
4134// Get QuantizeInfo *
4135MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4136{
4137 return _imgRef->options()->quantizeInfo();
4138}
4139const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4140{
4141 return _imgRef->options()->quantizeInfo();
4142}
4143
4144//
4145// Replace current image
4146//
4147MagickCore::Image * Magick::Image::replaceImage
4148 ( MagickCore::Image* replacement_ )
4149{
4150 MagickCore::Image* image;
4151
4152 if( replacement_ )
4153 image = replacement_;
4154 else
4155 image = AcquireImage(constImageInfo());
4156
4157 {
4158 Lock( &_imgRef->_mutexLock );
4159
4160 if ( _imgRef->_refCount == 1 )
4161 {
4162 // We own the image, just replace it, and de-register
4163 _imgRef->id( -1 );
4164 _imgRef->image(image);
4165 }
4166 else
4167 {
4168 // We don't own the image, dereference and replace with copy
4169 --_imgRef->_refCount;
4170 _imgRef = new ImageRef( image, constOptions() );
4171 }
4172 }
4173
4174 return _imgRef->_image;
4175}
4176
4177//
4178// Prepare to modify image or image options
4179// Replace current image and options with copy if reference count > 1
4180//
4181void Magick::Image::modifyImage( void )
4182{
4183 {
4184 Lock( &_imgRef->_mutexLock );
4185 if ( _imgRef->_refCount == 1 )
4186 {
4187 // De-register image and return
4188 _imgRef->id( -1 );
4189 return;
4190 }
4191 }
4192
4193 ExceptionInfo exceptionInfo;
4194 GetExceptionInfo( &exceptionInfo );
4195 replaceImage( CloneImage( image(),
4196 0, // columns
4197 0, // rows
4198 MagickTrue, // orphan
4199 &exceptionInfo) );
4200 throwException( exceptionInfo );
4201 (void) DestroyExceptionInfo( &exceptionInfo );
4202 return;
4203}
4204
4205//
4206// Test for an ImageMagick reported error and throw exception if one
4207// has been reported. Secretly resets image->exception back to default
4208// state even though this method is const.
4209//
4210void Magick::Image::throwImageException( void ) const
4211{
4212 // Throw C++ exception while resetting Image exception to default state
4213 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4214}
4215
4216// Register image with image registry or obtain registration id
cristybb503372010-05-27 20:51:26 +00004217ssize_t Magick::Image::registerId( void )
cristy3ed852e2009-09-05 21:47:34 +00004218{
4219 Lock( &_imgRef->_mutexLock );
4220 if( _imgRef->id() < 0 )
4221 {
4222 char id[MaxTextExtent];
4223 ExceptionInfo exceptionInfo;
4224 GetExceptionInfo( &exceptionInfo );
4225 _imgRef->id(_imgRef->id()+1);
cristye8c25f92010-06-03 00:53:06 +00004226 sprintf(id,"%.20g\n",(double) _imgRef->id());
cristy3ed852e2009-09-05 21:47:34 +00004227 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4228 throwException( exceptionInfo );
4229 (void) DestroyExceptionInfo( &exceptionInfo );
4230 }
4231 return _imgRef->id();
4232}
4233
4234// Unregister image from image registry
4235void Magick::Image::unregisterId( void )
4236{
4237 modifyImage();
4238 _imgRef->id( -1 );
4239}
4240
4241//
4242// Create a local wrapper around MagickCoreTerminus
4243//
4244namespace Magick
4245{
4246 extern "C" {
4247 void MagickPlusPlusDestroyMagick(void);
4248 }
4249}
4250
4251void Magick::MagickPlusPlusDestroyMagick(void)
4252{
4253 if (magick_initialized)
4254 {
4255 magick_initialized=false;
4256 MagickCore::MagickCoreTerminus();
4257 }
4258}
4259
4260// C library initialization routine
4261void MagickDLLDecl Magick::InitializeMagick(const char *path_)
4262{
4263 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4264 if (!magick_initialized)
4265 magick_initialized=true;
4266}
4267
4268//
4269// Cleanup class to ensure that ImageMagick singletons are destroyed
4270// so as to avoid any resemblence to a memory leak (which seems to
4271// confuse users)
4272//
4273namespace Magick
4274{
4275
4276 class MagickCleanUp
4277 {
4278 public:
4279 MagickCleanUp( void );
4280 ~MagickCleanUp( void );
4281 };
4282
4283 // The destructor for this object is invoked when the destructors for
4284 // static objects in this translation unit are invoked.
4285 static MagickCleanUp magickCleanUpGuard;
4286}
4287
4288Magick::MagickCleanUp::MagickCleanUp ( void )
4289{
4290 // Don't even think about invoking InitializeMagick here!
4291}
4292
4293Magick::MagickCleanUp::~MagickCleanUp ( void )
4294{
4295 MagickPlusPlusDestroyMagick();
4296}