blob: 42a6f710fada451c056fcfcd4909b9bb11f40171 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4//
5// Implementation of Image
6//
7
8#define MAGICKCORE_IMPLEMENTATION 1
9#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
10
cristy3ed852e2009-09-05 21:47:34 +000011#include <cstdlib>
12#include <string>
13#include <string.h>
14#include <errno.h>
15#include <math.h>
cristy4c08aed2011-07-01 19:47:50 +000016#include "Magick++/Include.h"
cristy3ed852e2009-09-05 21:47:34 +000017
18using namespace std;
19
20#include "Magick++/Image.h"
21#include "Magick++/Functions.h"
22#include "Magick++/Pixels.h"
23#include "Magick++/Options.h"
24#include "Magick++/ImageRef.h"
25
26#define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
cristy3ed852e2009-09-05 21:47:34 +000027#define DegreesToRadians(x) (MagickPI*(x)/180.0)
28
cristyaf1dd252011-09-07 19:04:02 +000029MagickPPExport const char *Magick::borderGeometryDefault = "6x6+0+0";
30MagickPPExport const char *Magick::frameGeometryDefault = "25x25+6+6";
31MagickPPExport const char *Magick::raiseGeometryDefault = "6x6+0+0";
cristy3ed852e2009-09-05 21:47:34 +000032
33static bool magick_initialized=false;
34
35//
36// Explicit template instantiations
37//
38
39//
40// Friend functions to compare Image objects
41//
42
cristyaf1dd252011-09-07 19:04:02 +000043MagickPPExport int Magick::operator == ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000044 const Magick::Image& right_ )
45{
46 // If image pixels and signature are the same, then the image is identical
47 return ( ( left_.rows() == right_.rows() ) &&
48 ( left_.columns() == right_.columns() ) &&
49 ( left_.signature() == right_.signature() )
50 );
51}
cristyaf1dd252011-09-07 19:04:02 +000052MagickPPExport int Magick::operator != ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000053 const Magick::Image& right_ )
54{
55 return ( ! (left_ == right_) );
56}
cristyaf1dd252011-09-07 19:04:02 +000057MagickPPExport int Magick::operator > ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000058 const Magick::Image& right_ )
59{
60 return ( !( left_ < right_ ) && ( left_ != right_ ) );
61}
cristyaf1dd252011-09-07 19:04:02 +000062MagickPPExport int Magick::operator < ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000063 const Magick::Image& right_ )
64{
65 // If image pixels are less, then image is smaller
66 return ( ( left_.rows() * left_.columns() ) <
67 ( right_.rows() * right_.columns() )
68 );
69}
cristyaf1dd252011-09-07 19:04:02 +000070MagickPPExport int Magick::operator >= ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000071 const Magick::Image& right_ )
72{
73 return ( ( left_ > right_ ) || ( left_ == right_ ) );
74}
cristyaf1dd252011-09-07 19:04:02 +000075MagickPPExport int Magick::operator <= ( const Magick::Image& left_,
cristy3ed852e2009-09-05 21:47:34 +000076 const Magick::Image& right_ )
77{
78 return ( ( left_ < right_ ) || ( left_ == right_ ) );
79}
80
81//
82// Image object implementation
83//
84
85// Construct from image file or image specification
86Magick::Image::Image( const std::string &imageSpec_ )
87 : _imgRef(new ImageRef)
88{
89 try
90 {
91 // Initialize, Allocate and Read images
92 read( imageSpec_ );
93 }
94 catch ( const Warning & /*warning_*/ )
95 {
96 // FIXME: need a way to report warnings in constructor
97 }
98 catch ( const Error & /*error_*/ )
99 {
100 // Release resources
101 delete _imgRef;
102 throw;
103 }
104}
105
106// Construct a blank image canvas of specified size and color
107Magick::Image::Image( const Geometry &size_,
108 const Color &color_ )
109 : _imgRef(new ImageRef)
110{
111 // xc: prefix specifies an X11 color string
112 std::string imageSpec("xc:");
113 imageSpec += color_;
114
115 try
116 {
117 // Set image size
118 size( size_ );
119
120 // Initialize, Allocate and Read images
121 read( imageSpec );
122 }
123 catch ( const Warning & /*warning_*/ )
124 {
125 // FIXME: need a way to report warnings in constructor
126 }
127 catch ( const Error & /*error_*/ )
128 {
129 // Release resources
130 delete _imgRef;
131 throw;
132 }
133}
134
135// Construct Image from in-memory BLOB
136Magick::Image::Image ( const Blob &blob_ )
137 : _imgRef(new ImageRef)
138{
139 try
140 {
141 // Initialize, Allocate and Read images
142 read( blob_ );
143 }
144 catch ( const Warning & /*warning_*/ )
145 {
146 // FIXME: need a way to report warnings in constructor
147 }
148 catch ( const Error & /*error_*/ )
149 {
150 // Release resources
151 delete _imgRef;
152 throw;
153 }
154}
155
156// Construct Image of specified size from in-memory BLOB
157Magick::Image::Image ( const Blob &blob_,
158 const Geometry &size_ )
159 : _imgRef(new ImageRef)
160{
161 try
162 {
163 // Read from Blob
164 read( blob_, size_ );
165 }
166 catch ( const Warning & /*warning_*/ )
167 {
168 // FIXME: need a way to report warnings in constructor
169 }
170 catch ( const Error & /*error_*/ )
171 {
172 // Release resources
173 delete _imgRef;
174 throw;
175 }
176}
177
178// Construct Image of specified size and depth from in-memory BLOB
179Magick::Image::Image ( const Blob &blob_,
180 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +0000181 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +0000182 : _imgRef(new ImageRef)
183{
184 try
185 {
186 // Read from Blob
187 read( blob_, size_, depth_ );
188 }
189 catch ( const Warning & /*warning_*/ )
190 {
191 // FIXME: need a way to report warnings in constructor
192 }
193 catch ( const Error & /*error_*/ )
194 {
195 // Release resources
196 delete _imgRef;
197 throw;
198 }
199}
200
201// Construct Image of specified size, depth, and format from in-memory BLOB
202Magick::Image::Image ( const Blob &blob_,
203 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +0000204 const size_t depth_,
cristy3ed852e2009-09-05 21:47:34 +0000205 const std::string &magick_ )
206 : _imgRef(new ImageRef)
207{
208 try
209 {
210 // Read from Blob
211 read( blob_, size_, depth_, magick_ );
212 }
213 catch ( const Warning & /*warning_*/ )
214 {
215 // FIXME: need a way to report warnings in constructor
216 }
217 catch ( const Error & /*error_*/ )
218 {
219 // Release resources
220 delete _imgRef;
221 throw;
222 }
223}
224
225// Construct Image of specified size, and format from in-memory BLOB
226Magick::Image::Image ( const Blob &blob_,
227 const Geometry &size_,
228 const std::string &magick_ )
229 : _imgRef(new ImageRef)
230{
231 try
232 {
233 // Read from Blob
234 read( blob_, size_, magick_ );
235 }
236 catch ( const Warning & /*warning_*/ )
237 {
238 // FIXME: need a way to report warnings in constructor
239 }
240 catch ( const Error & /*error_*/ )
241 {
242 // Release resources
243 delete _imgRef;
244 throw;
245 }
246}
247
248// Construct an image based on an array of raw pixels, of specified
249// type and mapping, in memory
cristyeaedf062010-05-29 22:36:02 +0000250Magick::Image::Image ( const size_t width_,
251 const size_t height_,
cristy3ed852e2009-09-05 21:47:34 +0000252 const std::string &map_,
253 const StorageType type_,
254 const void *pixels_ )
255 : _imgRef(new ImageRef)
256{
257 try
258 {
259 read( width_, height_, map_.c_str(), type_, pixels_ );
260 }
261 catch ( const Warning & /*warning_*/ )
262 {
263 // FIXME: need a way to report warnings in constructor
264 }
265 catch ( const Error & /*error_*/ )
266 {
267 // Release resources
268 delete _imgRef;
269 throw;
270 }
271}
272
273// Default constructor
274Magick::Image::Image( void )
275 : _imgRef(new ImageRef)
276{
277}
278
279// Destructor
280/* virtual */
281Magick::Image::~Image()
282{
283 bool doDelete = false;
284 {
285 Lock( &_imgRef->_mutexLock );
286 if ( --_imgRef->_refCount == 0 )
287 doDelete = true;
288 }
289
290 if ( doDelete )
291 {
292 delete _imgRef;
293 }
294 _imgRef = 0;
295}
296
297// Adaptive-blur image
298void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
299{
300 ExceptionInfo exceptionInfo;
301 GetExceptionInfo( &exceptionInfo );
302 MagickCore::Image* newImage =
cristy4c11c2b2011-09-05 20:17:07 +0000303 AdaptiveBlurImage( image(), radius_, sigma_, image()->bias, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +0000304 replaceImage( newImage );
305 throwException( exceptionInfo );
306 (void) DestroyExceptionInfo( &exceptionInfo );
307}
308
309// Local adaptive threshold image
310// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
311// Width x height define the size of the pixel neighborhood
312// offset = constant to subtract from pixel neighborhood mean
cristyeaedf062010-05-29 22:36:02 +0000313void Magick::Image::adaptiveThreshold ( const size_t width_,
314 const size_t height_,
cristy4e0eef02010-05-30 21:52:21 +0000315 const ssize_t offset_ )
cristy3ed852e2009-09-05 21:47:34 +0000316{
317 ExceptionInfo exceptionInfo;
318 GetExceptionInfo( &exceptionInfo );
319 MagickCore::Image* newImage =
320 AdaptiveThresholdImage( constImage(), width_, height_, offset_, &exceptionInfo );
321 replaceImage( newImage );
322 throwException( exceptionInfo );
323 (void) DestroyExceptionInfo( &exceptionInfo );
324}
325
326// Add noise to image
327void Magick::Image::addNoise( const NoiseType noiseType_ )
328{
329 ExceptionInfo exceptionInfo;
330 GetExceptionInfo( &exceptionInfo );
331 MagickCore::Image* newImage =
332 AddNoiseImage ( image(),
333 noiseType_,
334 &exceptionInfo );
335 replaceImage( newImage );
336 throwException( exceptionInfo );
337 (void) DestroyExceptionInfo( &exceptionInfo );
338}
339
340void Magick::Image::addNoiseChannel( const ChannelType channel_,
341 const NoiseType noiseType_ )
342{
343 ExceptionInfo exceptionInfo;
344 GetExceptionInfo( &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +0000345 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
cristy3ed852e2009-09-05 21:47:34 +0000346 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +0000347 AddNoiseImage ( image(),
cristy3ed852e2009-09-05 21:47:34 +0000348 noiseType_,
349 &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +0000350 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +0000351 replaceImage( newImage );
352 throwException( exceptionInfo );
353 (void) DestroyExceptionInfo( &exceptionInfo );
354}
355
356// Affine Transform image
357void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
358{
359 ExceptionInfo exceptionInfo;
360 GetExceptionInfo( &exceptionInfo );
361
362 AffineMatrix _affine;
363 _affine.sx = affine_.sx();
364 _affine.sy = affine_.sy();
365 _affine.rx = affine_.rx();
366 _affine.ry = affine_.ry();
367 _affine.tx = affine_.tx();
368 _affine.ty = affine_.ty();
369
370 MagickCore::Image* newImage =
371 AffineTransformImage( image(), &_affine, &exceptionInfo);
372 replaceImage( newImage );
373 throwException( exceptionInfo );
374 (void) DestroyExceptionInfo( &exceptionInfo );
375}
376
377// Annotate using specified text, and placement location
378void Magick::Image::annotate ( const std::string &text_,
379 const Geometry &location_ )
380{
381 annotate ( text_, location_, NorthWestGravity, 0.0 );
382}
383// Annotate using specified text, bounding area, and placement gravity
384void Magick::Image::annotate ( const std::string &text_,
385 const Geometry &boundingArea_,
386 const GravityType gravity_ )
387{
388 annotate ( text_, boundingArea_, gravity_, 0.0 );
389}
390// Annotate with text using specified text, bounding area, placement
391// gravity, and rotation.
392void Magick::Image::annotate ( const std::string &text_,
393 const Geometry &boundingArea_,
394 const GravityType gravity_,
395 const double degrees_ )
396{
397 modifyImage();
398
399 DrawInfo *drawInfo
400 = options()->drawInfo();
401
402 drawInfo->text = const_cast<char *>(text_.c_str());
403
404 char boundingArea[MaxTextExtent];
405
406 drawInfo->geometry = 0;
407 if ( boundingArea_.isValid() ){
408 if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
409 {
cristyb51dff52011-05-19 16:55:47 +0000410 FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
cristyfe0019b2010-06-07 02:23:32 +0000411 (double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
cristy3ed852e2009-09-05 21:47:34 +0000412 }
413 else
414 {
415 (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
416 MaxTextExtent);
417 }
418 drawInfo->geometry = boundingArea;
419 }
420
421 drawInfo->gravity = gravity_;
422
423 AffineMatrix oaffine = drawInfo->affine;
424 if ( degrees_ != 0.0)
425 {
426 AffineMatrix affine;
427 affine.sx=1.0;
428 affine.rx=0.0;
429 affine.ry=0.0;
430 affine.sy=1.0;
431 affine.tx=0.0;
432 affine.ty=0.0;
433
434 AffineMatrix current = drawInfo->affine;
435 affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
436 affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
437 affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
438 affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
439
440 drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
441 drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
442 drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
443 drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
444 drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
445 +current.tx;
446 }
447
cristy5cbc0162011-08-29 00:36:28 +0000448 ExceptionInfo exceptionInfo;
449 GetExceptionInfo( &exceptionInfo );
450 AnnotateImage( image(), drawInfo, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000451
452 // Restore original values
453 drawInfo->affine = oaffine;
454 drawInfo->text = 0;
455 drawInfo->geometry = 0;
456
cristy5cbc0162011-08-29 00:36:28 +0000457 throwException( exceptionInfo );
458 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000459}
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
cristy5cbc0162011-08-29 00:36:28 +0000473 ExceptionInfo exceptionInfo;
474 GetExceptionInfo( &exceptionInfo );
475 AnnotateImage( image(), drawInfo, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000476
477 drawInfo->gravity = NorthWestGravity;
478 drawInfo->text = 0;
479
cristy5cbc0162011-08-29 00:36:28 +0000480 throwException( exceptionInfo );
481 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000482}
483
484// Blur image
485void Magick::Image::blur( const double radius_, const double sigma_ )
486{
487 ExceptionInfo exceptionInfo;
488 GetExceptionInfo( &exceptionInfo );
489 MagickCore::Image* newImage =
cristy05c0c9a2011-09-05 23:16:13 +0000490 BlurImage( image(), radius_, sigma_, image()->bias, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +0000491 replaceImage( newImage );
492 throwException( exceptionInfo );
493 (void) DestroyExceptionInfo( &exceptionInfo );
494}
495
496void Magick::Image::blurChannel( const ChannelType channel_,
497 const double radius_, const double sigma_ )
498{
499 ExceptionInfo exceptionInfo;
500 GetExceptionInfo( &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +0000501 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +0000502 MagickCore::Image* newImage =
cristy05c0c9a2011-09-05 23:16:13 +0000503 BlurImage( image(), radius_, sigma_, image()->bias, &exceptionInfo);
cristybd5a96c2011-08-21 00:04:26 +0000504 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +0000505 replaceImage( newImage );
506 throwException( exceptionInfo );
507 (void) DestroyExceptionInfo( &exceptionInfo );
508}
509
510// Add border to image
511// Only uses width & height
512void Magick::Image::border( const Geometry &geometry_ )
513{
514 RectangleInfo borderInfo = geometry_;
515 ExceptionInfo exceptionInfo;
516 GetExceptionInfo( &exceptionInfo );
517 MagickCore::Image* newImage =
cristy633f0c62011-09-15 13:27:36 +0000518 BorderImage( image(), &borderInfo, image()->compose, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +0000519 replaceImage( newImage );
520 throwException( exceptionInfo );
521 (void) DestroyExceptionInfo( &exceptionInfo );
522}
523
524// Extract channel from image
525void Magick::Image::channel ( const ChannelType channel_ )
526{
527 modifyImage();
cristybd5a96c2011-08-21 00:04:26 +0000528 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
cristy3139dc22011-07-08 00:11:42 +0000529 SeparateImage ( image() );
cristybd5a96c2011-08-21 00:04:26 +0000530 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +0000531 throwImageException();
532}
533
534// Set or obtain modulus channel depth
cristyfefab1b2011-07-05 00:33:22 +0000535void Magick::Image::channelDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +0000536{
537 modifyImage();
cristyfefab1b2011-07-05 00:33:22 +0000538 SetImageDepth( image(), depth_);
cristy3ed852e2009-09-05 21:47:34 +0000539 throwImageException();
540}
cristyfefab1b2011-07-05 00:33:22 +0000541size_t Magick::Image::channelDepth ( )
cristy3ed852e2009-09-05 21:47:34 +0000542{
cristyeaedf062010-05-29 22:36:02 +0000543 size_t channel_depth;
cristy3ed852e2009-09-05 21:47:34 +0000544
545 ExceptionInfo exceptionInfo;
546 GetExceptionInfo( &exceptionInfo );
cristyfefab1b2011-07-05 00:33:22 +0000547 channel_depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000548 throwException( exceptionInfo );
549 (void) DestroyExceptionInfo( &exceptionInfo );
550 return channel_depth;
551}
552
553
554// Charcoal-effect image
555void Magick::Image::charcoal( const double radius_, const double sigma_ )
556{
557 ExceptionInfo exceptionInfo;
558 GetExceptionInfo( &exceptionInfo );
559 MagickCore::Image* newImage =
cristy05c0c9a2011-09-05 23:16:13 +0000560 CharcoalImage( image(), radius_, sigma_, image()->bias, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000561 replaceImage( newImage );
562 throwException( exceptionInfo );
563 (void) DestroyExceptionInfo( &exceptionInfo );
564}
565
566// Chop image
567void Magick::Image::chop( const Geometry &geometry_ )
568{
569 RectangleInfo chopInfo = geometry_;
570 ExceptionInfo exceptionInfo;
571 GetExceptionInfo( &exceptionInfo );
572 MagickCore::Image* newImage =
573 ChopImage( image(), &chopInfo, &exceptionInfo);
574 replaceImage( newImage );
575 throwException( exceptionInfo );
576 (void) DestroyExceptionInfo( &exceptionInfo );
577}
578
cristyb32b90a2009-09-07 21:45:48 +0000579// contains one or more color corrections and applies the correction to the
580// image.
581void Magick::Image::cdl ( const std::string &cdl_ )
582{
583 modifyImage();
cristy1bfa9f02011-08-11 02:35:43 +0000584 ExceptionInfo exceptionInfo;
585 GetExceptionInfo( &exceptionInfo );
586 (void) ColorDecisionListImage( image(), cdl_.c_str(), &exceptionInfo );
587 throwException( exceptionInfo );
588 (void) DestroyExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +0000589}
590
cristy3ed852e2009-09-05 21:47:34 +0000591// Colorize
cristy4c08aed2011-07-01 19:47:50 +0000592void Magick::Image::colorize ( const unsigned int alphaRed_,
593 const unsigned int alphaGreen_,
594 const unsigned int alphaBlue_,
cristy3ed852e2009-09-05 21:47:34 +0000595 const Color &penColor_ )
596{
597 if ( !penColor_.isValid() )
598 {
599 throwExceptionExplicit( OptionError,
600 "Pen color argument is invalid");
601 }
602
cristy4c08aed2011-07-01 19:47:50 +0000603 char alpha[MaxTextExtent];
604 FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_);
cristy3ed852e2009-09-05 21:47:34 +0000605
606 ExceptionInfo exceptionInfo;
607 GetExceptionInfo( &exceptionInfo );
608 MagickCore::Image* newImage =
cristy4c08aed2011-07-01 19:47:50 +0000609 ColorizeImage ( image(), alpha,
cristy3ed852e2009-09-05 21:47:34 +0000610 penColor_, &exceptionInfo );
611 replaceImage( newImage );
612 throwException( exceptionInfo );
613 (void) DestroyExceptionInfo( &exceptionInfo );
614}
cristy4c08aed2011-07-01 19:47:50 +0000615void Magick::Image::colorize ( const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +0000616 const Color &penColor_ )
617{
cristy4c08aed2011-07-01 19:47:50 +0000618 colorize( alpha_, alpha_, alpha_, penColor_ );
cristy3ed852e2009-09-05 21:47:34 +0000619}
620
cristy735e8942010-04-02 20:32:57 +0000621// Apply a color matrix to the image channels. The user supplied
622// matrix may be of order 1 to 6 (1x1 through 6x6).
cristyeaedf062010-05-29 22:36:02 +0000623void Magick::Image::colorMatrix (const size_t order_,
cristyc8918bb2010-04-03 01:57:27 +0000624 const double *color_matrix_)
cristy735e8942010-04-02 20:32:57 +0000625{
cristyc8918bb2010-04-03 01:57:27 +0000626 KernelInfo
627 *kernel_info;
628
cristy735e8942010-04-02 20:32:57 +0000629 ExceptionInfo exceptionInfo;
630 GetExceptionInfo( &exceptionInfo );
cristy5e6be1e2011-07-16 01:23:39 +0000631 kernel_info=AcquireKernelInfo((const char *) NULL);
cristyc8918bb2010-04-03 01:57:27 +0000632 kernel_info->width=order_;
633 kernel_info->height=order_;
cristyc8918bb2010-04-03 01:57:27 +0000634 kernel_info->values=(double *) color_matrix_;
cristy735e8942010-04-02 20:32:57 +0000635 MagickCore::Image* newImage =
cristyc8918bb2010-04-03 01:57:27 +0000636 ColorMatrixImage( image(), kernel_info, &exceptionInfo );
cristya2175d32010-04-03 02:25:17 +0000637 kernel_info->values=(double *) NULL;
cristyc8918bb2010-04-03 01:57:27 +0000638 kernel_info=DestroyKernelInfo(kernel_info);
cristy735e8942010-04-02 20:32:57 +0000639 replaceImage( newImage );
640 throwException( exceptionInfo );
641 (void) DestroyExceptionInfo( &exceptionInfo );
642}
643
cristy3ed852e2009-09-05 21:47:34 +0000644// Compare current image with another image
645// Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
646// in the current image. False is returned if the images are identical.
647bool Magick::Image::compare ( const Image &reference_ )
648{
cristy018f07f2011-09-04 21:15:19 +0000649 ExceptionInfo exceptionInfo;
650 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000651 modifyImage();
652 Image ref = reference_;
653 ref.modifyImage();
cristy018f07f2011-09-04 21:15:19 +0000654 bool status =
655 static_cast<bool>(IsImagesEqual(image(), ref.image(), &exceptionInfo));
656 throwException( exceptionInfo );
657 (void) DestroyExceptionInfo( &exceptionInfo );
658 return status;
cristy3ed852e2009-09-05 21:47:34 +0000659}
660
661// Composite two images
662void Magick::Image::composite ( const Image &compositeImage_,
cristyd99b0962010-05-29 23:14:26 +0000663 const ssize_t xOffset_,
664 const ssize_t yOffset_,
cristy3ed852e2009-09-05 21:47:34 +0000665 const CompositeOperator compose_ )
666{
667 // Image supplied as compositeImage is composited with current image and
668 // results in updating current image.
669 modifyImage();
670
671 CompositeImage( image(),
672 compose_,
673 compositeImage_.constImage(),
674 xOffset_,
675 yOffset_ );
676 throwImageException();
677}
678void Magick::Image::composite ( const Image &compositeImage_,
679 const Geometry &offset_,
680 const CompositeOperator compose_ )
681{
682 modifyImage();
683
cristybb503372010-05-27 20:51:26 +0000684 ssize_t x = offset_.xOff();
685 ssize_t y = offset_.yOff();
686 size_t width = columns();
687 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +0000688
689 ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
690 &x, &y,
691 &width, &height );
692
693 CompositeImage( image(),
694 compose_,
695 compositeImage_.constImage(),
696 x, y );
697 throwImageException();
698}
699void Magick::Image::composite ( const Image &compositeImage_,
700 const GravityType gravity_,
701 const CompositeOperator compose_ )
702{
703 modifyImage();
704
705 RectangleInfo geometry;
706
707 SetGeometry(compositeImage_.constImage(), &geometry);
708 GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
709
710 CompositeImage( image(),
711 compose_,
712 compositeImage_.constImage(),
713 geometry.x, geometry.y );
714 throwImageException();
715}
716
717// Contrast image
cristyeaedf062010-05-29 22:36:02 +0000718void Magick::Image::contrast ( const size_t sharpen_ )
cristy3ed852e2009-09-05 21:47:34 +0000719{
720 modifyImage();
cristye23ec9d2011-08-16 18:15:40 +0000721 ExceptionInfo exceptionInfo;
722 GetExceptionInfo( &exceptionInfo );
723 ContrastImage ( image(), (MagickBooleanType) sharpen_, &exceptionInfo );
724 throwException( exceptionInfo );
725 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000726}
727
728// Convolve image. Applies a general image convolution kernel to the image.
729// order_ represents the number of columns and rows in the filter kernel.
730// kernel_ is an array of doubles representing the convolution kernel.
cristyeaedf062010-05-29 22:36:02 +0000731void Magick::Image::convolve ( const size_t order_,
cristy3ed852e2009-09-05 21:47:34 +0000732 const double *kernel_ )
733{
cristy5e6be1e2011-07-16 01:23:39 +0000734 KernelInfo
735 *kernel_info;
736
cristy3ed852e2009-09-05 21:47:34 +0000737 ExceptionInfo exceptionInfo;
738 GetExceptionInfo( &exceptionInfo );
cristy5e6be1e2011-07-16 01:23:39 +0000739 kernel_info=AcquireKernelInfo((const char *) NULL);
740 kernel_info->width=order_;
741 kernel_info->height=order_;
742 kernel_info->values=(double *) kernel_;
cristy0a922382011-07-16 15:30:34 +0000743 kernel_info->bias=image()->bias;
cristy3ed852e2009-09-05 21:47:34 +0000744 MagickCore::Image* newImage =
cristy5e6be1e2011-07-16 01:23:39 +0000745 ConvolveImage ( image(), kernel_info, &exceptionInfo );
746 kernel_info->values=(double *) NULL;
747 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +0000748 replaceImage( newImage );
749 throwException( exceptionInfo );
750 (void) DestroyExceptionInfo( &exceptionInfo );
751}
752
753// Crop image
754void Magick::Image::crop ( const Geometry &geometry_ )
755{
756 RectangleInfo cropInfo = geometry_;
757 ExceptionInfo exceptionInfo;
758 GetExceptionInfo( &exceptionInfo );
759 MagickCore::Image* newImage =
760 CropImage( image(),
761 &cropInfo,
762 &exceptionInfo);
763 replaceImage( newImage );
764 throwException( exceptionInfo );
765 (void) DestroyExceptionInfo( &exceptionInfo );
766}
767
768// Cycle Color Map
cristyd99b0962010-05-29 23:14:26 +0000769void Magick::Image::cycleColormap ( const ssize_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +0000770{
cristy018f07f2011-09-04 21:15:19 +0000771 ExceptionInfo exceptionInfo;
772 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000773 modifyImage();
cristy018f07f2011-09-04 21:15:19 +0000774 CycleColormapImage( image(), amount_, &exceptionInfo );
775 throwException( exceptionInfo );
776 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000777}
778
779// Despeckle
780void Magick::Image::despeckle ( void )
781{
782 ExceptionInfo exceptionInfo;
783 GetExceptionInfo( &exceptionInfo );
784 MagickCore::Image* newImage =
785 DespeckleImage( image(), &exceptionInfo );
786 replaceImage( newImage );
787 throwException( exceptionInfo );
788 (void) DestroyExceptionInfo( &exceptionInfo );
789}
790
791// Display image
792void Magick::Image::display( void )
793{
cristy051718b2011-08-28 22:49:25 +0000794 ExceptionInfo exceptionInfo;
795 GetExceptionInfo( &exceptionInfo );
796 DisplayImages( imageInfo(), image(), &exceptionInfo );
797 throwException( exceptionInfo );
798 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000799}
800
801// Distort image. distorts an image using various distortion methods, by
802// mapping color lookups of the source image to a new destination image
803// usally of the same size as the source image, unless 'bestfit' is set to
804// true.
cristyb32b90a2009-09-07 21:45:48 +0000805void Magick::Image::distort ( const DistortImageMethod method_,
cristybb503372010-05-27 20:51:26 +0000806 const size_t number_arguments_,
cristyb32b90a2009-09-07 21:45:48 +0000807 const double *arguments_,
808 const bool bestfit_ )
cristy3ed852e2009-09-05 21:47:34 +0000809{
810 ExceptionInfo exceptionInfo;
811 GetExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +0000812 MagickCore::Image* newImage = DistortImage ( image(), method_,
813 number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
814 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000815 replaceImage( newImage );
816 throwException( exceptionInfo );
817 (void) DestroyExceptionInfo( &exceptionInfo );
818}
819
820// Draw on image using single drawable
821void Magick::Image::draw ( const Magick::Drawable &drawable_ )
822{
823 modifyImage();
824
825 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
826
827 if(wand)
828 {
829 drawable_.operator()(wand);
830
831 if( constImage()->exception.severity == UndefinedException)
832 DrawRender(wand);
833
834 wand=DestroyDrawingWand(wand);
835 }
836
837 throwImageException();
838}
839
840// Draw on image using a drawable list
841void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
842{
843 modifyImage();
844
845 DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
846
847 if(wand)
848 {
849 for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
850 p != drawable_.end(); p++ )
851 {
852 p->operator()(wand);
853 if( constImage()->exception.severity != UndefinedException)
854 break;
855 }
856
857 if( constImage()->exception.severity == UndefinedException)
858 DrawRender(wand);
859
860 wand=DestroyDrawingWand(wand);
861 }
862
863 throwImageException();
864}
865
866// Hilight edges in image
cristy8ae632d2011-09-05 17:29:53 +0000867void Magick::Image::edge ( const double radius_, const double sigma_ )
868{
869 ExceptionInfo exceptionInfo;
870 GetExceptionInfo( &exceptionInfo );
871 MagickCore::Image* newImage =
872 EdgeImage( image(), radius_, sigma_, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000873 replaceImage( newImage );
874 throwException( exceptionInfo );
875 (void) DestroyExceptionInfo( &exceptionInfo );
876}
877
878// Emboss image (hilight edges)
879void Magick::Image::emboss ( const double radius_, const double sigma_ )
880{
881 ExceptionInfo exceptionInfo;
882 GetExceptionInfo( &exceptionInfo );
883 MagickCore::Image* newImage =
884 EmbossImage( image(), radius_, sigma_, &exceptionInfo );
885 replaceImage( newImage );
886 throwException( exceptionInfo );
887 (void) DestroyExceptionInfo( &exceptionInfo );
888}
889
890// Enhance image (minimize noise)
891void Magick::Image::enhance ( void )
892{
893 ExceptionInfo exceptionInfo;
894 GetExceptionInfo( &exceptionInfo );
895 MagickCore::Image* newImage =
896 EnhanceImage( image(), &exceptionInfo );
897 replaceImage( newImage );
898 throwException( exceptionInfo );
899 (void) DestroyExceptionInfo( &exceptionInfo );
900}
901
902// Equalize image (histogram equalization)
903void Magick::Image::equalize ( void )
904{
cristy6d8c3d72011-08-22 01:20:01 +0000905 ExceptionInfo exceptionInfo;
906 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000907 modifyImage();
cristy6d8c3d72011-08-22 01:20:01 +0000908 EqualizeImage( image(), &exceptionInfo );
909 throwException( exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +0000910}
911
912// Erase image to current "background color"
913void Magick::Image::erase ( void )
914{
915 modifyImage();
916 SetImageBackgroundColor( image() );
917 throwImageException();
918}
919
920// Extends image as defined by the geometry.
921//
922void Magick::Image::extent ( const Geometry &geometry_ )
923{
924 RectangleInfo extentInfo = geometry_;
925 modifyImage();
cristy8bf9e292010-02-21 17:48:01 +0000926 ExceptionInfo exceptionInfo;
927 GetExceptionInfo( &exceptionInfo );
cristy1ee42c42010-05-12 12:52:50 +0000928 MagickCore::Image* newImage =
929 ExtentImage ( image(), &extentInfo, &exceptionInfo );
930 replaceImage( newImage );
cristy8bf9e292010-02-21 17:48:01 +0000931 throwException( exceptionInfo );
932 (void) DestroyExceptionInfo( &exceptionInfo );
933}
934void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
935{
936 backgroundColor ( backgroundColor_ );
937 extent ( geometry_ );
938}
cristyff024b42010-02-21 22:55:09 +0000939void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
cristy8bf9e292010-02-21 17:48:01 +0000940{
941 image()->gravity = gravity_;
942 extent ( geometry_ );
943}
944void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
945{
946 image()->gravity = gravity_;
947 backgroundColor ( backgroundColor_ );
948 extent ( geometry_ );
cristy3ed852e2009-09-05 21:47:34 +0000949}
950
951// Flip image (reflect each scanline in the vertical direction)
952void Magick::Image::flip ( void )
953{
954 ExceptionInfo exceptionInfo;
955 GetExceptionInfo( &exceptionInfo );
956 MagickCore::Image* newImage =
957 FlipImage( image(), &exceptionInfo );
958 replaceImage( newImage );
959 throwException( exceptionInfo );
960 (void) DestroyExceptionInfo( &exceptionInfo );
961}
962
963// Flood-fill color across pixels that match the color of the
964// target pixel and are neighbors of the target pixel.
965// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000966void Magick::Image::floodFillColor( const ssize_t x_,
967 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000968 const Magick::Color &fillColor_ )
969{
970 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
971}
972void Magick::Image::floodFillColor( const Geometry &point_,
973 const Magick::Color &fillColor_ )
974{
975 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
976}
977
978// Flood-fill color across pixels starting at target-pixel and
979// stopping at pixels matching specified border color.
980// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +0000981void Magick::Image::floodFillColor( const ssize_t x_,
982 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +0000983 const Magick::Color &fillColor_,
984 const Magick::Color &borderColor_ )
985{
986 floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
987 borderColor_ );
988}
989void Magick::Image::floodFillColor( const Geometry &point_,
990 const Magick::Color &fillColor_,
991 const Magick::Color &borderColor_ )
992{
993 floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
994 borderColor_ );
995}
996
997// Floodfill pixels matching color (within fuzz factor) of target
cristy4c08aed2011-07-01 19:47:50 +0000998// pixel(x,y) with replacement alpha value using method.
cristy35ef8242010-06-03 16:24:13 +0000999void Magick::Image::floodFillOpacity( const ssize_t x_,
1000 const ssize_t y_,
cristy4c08aed2011-07-01 19:47:50 +00001001 const unsigned int alpha_,
cristy3ed852e2009-09-05 21:47:34 +00001002 const PaintMethod method_ )
1003{
1004 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001005 PixelInfo target;
1006 GetPixelInfo(image(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001007 PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
1008 target.red=pixel.red;
1009 target.green=pixel.green;
1010 target.blue=pixel.blue;
cristy4c08aed2011-07-01 19:47:50 +00001011 target.alpha=alpha_;
cristy189e84c2011-08-27 18:08:53 +00001012 ExceptionInfo exceptionInfo;
1013 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001014 FloodfillPaintImage ( image(),
cristy3ed852e2009-09-05 21:47:34 +00001015 options()->drawInfo(), // const DrawInfo *draw_info
1016 &target,
cristybb503372010-05-27 20:51:26 +00001017 static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
cristy189e84c2011-08-27 18:08:53 +00001018 method_ == FloodfillMethod ? MagickFalse : MagickTrue,
1019 &exceptionInfo);
1020 throwException( exceptionInfo );
1021 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001022}
1023
1024// Flood-fill texture across pixels that match the color of the
1025// target pixel and are neighbors of the target pixel.
1026// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +00001027void Magick::Image::floodFillTexture( const ssize_t x_,
1028 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001029 const Magick::Image &texture_ )
1030{
1031 modifyImage();
1032
1033 // Set drawing pattern
1034 options()->fillPattern(texture_.constImage());
1035
1036 // Get pixel view
1037 Pixels pixels(*this);
1038 // Fill image
cristy4c08aed2011-07-01 19:47:50 +00001039 Quantum *p = pixels.get(x_, y_, 1, 1 );
1040 PixelInfo target;
1041 GetPixelInfo(constImage(),&target);
1042 target.red=GetPixelRed(constImage(),p);
1043 target.green=GetPixelGreen(constImage(),p);
1044 target.blue=GetPixelBlue(constImage(),p);
cristy189e84c2011-08-27 18:08:53 +00001045 ExceptionInfo exceptionInfo;
1046 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001047 if (p)
1048 FloodfillPaintImage ( image(), // Image *image
cristy3ed852e2009-09-05 21:47:34 +00001049 options()->drawInfo(), // const DrawInfo *draw_info
1050 &target, // const MagickPacket target
cristybb503372010-05-27 20:51:26 +00001051 static_cast<ssize_t>(x_), // const ssize_t x_offset
1052 static_cast<ssize_t>(y_), // const ssize_t y_offset
cristy189e84c2011-08-27 18:08:53 +00001053 MagickFalse, // const PaintMethod method
1054 &exceptionInfo );
1055 throwException( exceptionInfo );
1056 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001057
cristy3ed852e2009-09-05 21:47:34 +00001058}
1059void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1060 const Magick::Image &texture_ )
1061{
1062 floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
1063}
1064
1065// Flood-fill texture across pixels starting at target-pixel and
1066// stopping at pixels matching specified border color.
1067// Uses current fuzz setting when determining color match.
cristy35ef8242010-06-03 16:24:13 +00001068void Magick::Image::floodFillTexture( const ssize_t x_,
1069 const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001070 const Magick::Image &texture_,
1071 const Magick::Color &borderColor_ )
1072{
1073 modifyImage();
1074
1075 // Set drawing fill pattern
1076 options()->fillPattern(texture_.constImage());
1077
cristy4c08aed2011-07-01 19:47:50 +00001078 PixelInfo target;
1079 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001080 target.red=static_cast<PixelPacket>(borderColor_).red;
1081 target.green=static_cast<PixelPacket>(borderColor_).green;
1082 target.blue=static_cast<PixelPacket>(borderColor_).blue;
cristy189e84c2011-08-27 18:08:53 +00001083 ExceptionInfo exceptionInfo;
1084 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001085 FloodfillPaintImage ( image(),
cristy3ed852e2009-09-05 21:47:34 +00001086 options()->drawInfo(),
1087 &target,
cristybb503372010-05-27 20:51:26 +00001088 static_cast<ssize_t>(x_),
1089 static_cast<ssize_t>(y_),
cristy189e84c2011-08-27 18:08:53 +00001090 MagickTrue, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00001091
cristy189e84c2011-08-27 18:08:53 +00001092 throwException( exceptionInfo );
1093 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001094}
1095void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
1096 const Magick::Image &texture_,
1097 const Magick::Color &borderColor_ )
1098{
1099 floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
1100}
1101
1102// Flop image (reflect each scanline in the horizontal direction)
1103void Magick::Image::flop ( void )
1104{
1105 ExceptionInfo exceptionInfo;
1106 GetExceptionInfo( &exceptionInfo );
1107 MagickCore::Image* newImage =
1108 FlopImage( image(), &exceptionInfo );
1109 replaceImage( newImage );
1110 throwException( exceptionInfo );
1111 (void) DestroyExceptionInfo( &exceptionInfo );
1112}
1113
1114// Frame image
1115void Magick::Image::frame ( const Geometry &geometry_ )
1116{
1117 FrameInfo info;
1118
cristybb503372010-05-27 20:51:26 +00001119 info.x = static_cast<ssize_t>(geometry_.width());
1120 info.y = static_cast<ssize_t>(geometry_.height());
1121 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1122 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
cristy3ed852e2009-09-05 21:47:34 +00001123 info.outer_bevel = geometry_.xOff();
1124 info.inner_bevel = geometry_.yOff();
1125
1126 ExceptionInfo exceptionInfo;
1127 GetExceptionInfo( &exceptionInfo );
1128 MagickCore::Image* newImage =
cristy633f0c62011-09-15 13:27:36 +00001129 FrameImage( image(), &info, image()->compose, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001130 replaceImage( newImage );
1131 throwException( exceptionInfo );
1132 (void) DestroyExceptionInfo( &exceptionInfo );
1133}
cristyeaedf062010-05-29 22:36:02 +00001134void Magick::Image::frame ( const size_t width_,
1135 const size_t height_,
cristyd99b0962010-05-29 23:14:26 +00001136 const ssize_t outerBevel_, const ssize_t innerBevel_ )
cristy3ed852e2009-09-05 21:47:34 +00001137{
1138 FrameInfo info;
cristybb503372010-05-27 20:51:26 +00001139 info.x = static_cast<ssize_t>(width_);
1140 info.y = static_cast<ssize_t>(height_);
1141 info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
1142 info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
1143 info.outer_bevel = static_cast<ssize_t>(outerBevel_);
1144 info.inner_bevel = static_cast<ssize_t>(innerBevel_);
cristy3ed852e2009-09-05 21:47:34 +00001145
1146 ExceptionInfo exceptionInfo;
1147 GetExceptionInfo( &exceptionInfo );
1148 MagickCore::Image* newImage =
cristy633f0c62011-09-15 13:27:36 +00001149 FrameImage( image(), &info, image()->compose, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001150 replaceImage( newImage );
1151 throwException( exceptionInfo );
1152 (void) DestroyExceptionInfo( &exceptionInfo );
1153}
1154
cristyc9550792009-11-13 20:05:42 +00001155// Fx image. Applies a mathematical expression to the image.
1156void Magick::Image::fx ( const std::string expression )
1157{
1158 ExceptionInfo exceptionInfo;
1159 GetExceptionInfo( &exceptionInfo );
1160 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001161 FxImage ( image(), expression.c_str(), &exceptionInfo );
cristyc9550792009-11-13 20:05:42 +00001162 replaceImage( newImage );
1163 throwException( exceptionInfo );
1164 (void) DestroyExceptionInfo( &exceptionInfo );
1165}
cristy3ed852e2009-09-05 21:47:34 +00001166void Magick::Image::fx ( const std::string expression,
1167 const Magick::ChannelType channel )
1168{
1169 ExceptionInfo exceptionInfo;
1170 GetExceptionInfo( &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001171 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
cristy3ed852e2009-09-05 21:47:34 +00001172 MagickCore::Image* newImage =
cristy490408a2011-07-07 14:42:05 +00001173 FxImage ( image(), expression.c_str(), &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001174 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +00001175 replaceImage( newImage );
1176 throwException( exceptionInfo );
1177 (void) DestroyExceptionInfo( &exceptionInfo );
1178}
1179
1180// Gamma correct image
1181void Magick::Image::gamma ( const double gamma_ )
1182{
cristyb3e7c6c2011-07-24 01:43:55 +00001183 ExceptionInfo exceptionInfo;
1184 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001185 modifyImage();
cristyb3e7c6c2011-07-24 01:43:55 +00001186 GammaImage ( image(), gamma_, &exceptionInfo );
1187 throwException( exceptionInfo );
1188 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001189}
1190
1191void Magick::Image::gamma ( const double gammaRed_,
1192 const double gammaGreen_,
1193 const double gammaBlue_ )
1194{
1195 char gamma[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001196 FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
cristy3ed852e2009-09-05 21:47:34 +00001197 gammaRed_, gammaGreen_, gammaBlue_);
1198
cristyb3e7c6c2011-07-24 01:43:55 +00001199 ExceptionInfo exceptionInfo;
1200 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001201 modifyImage();
cristyb3e7c6c2011-07-24 01:43:55 +00001202 GammaImage ( image(), atof(gamma), &exceptionInfo );
1203 throwException( exceptionInfo );
1204 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001205}
1206
1207// Gaussian blur image
1208// The number of neighbor pixels to be included in the convolution
1209// mask is specified by 'width_'. The standard deviation of the
1210// gaussian bell curve is specified by 'sigma_'.
1211void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
1212{
1213 ExceptionInfo exceptionInfo;
1214 GetExceptionInfo( &exceptionInfo );
1215 MagickCore::Image* newImage =
cristy05c0c9a2011-09-05 23:16:13 +00001216 GaussianBlurImage( image(), width_, sigma_, image()->bias, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001217 replaceImage( newImage );
1218 throwException( exceptionInfo );
1219 (void) DestroyExceptionInfo( &exceptionInfo );
1220}
1221
1222void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
1223 const double width_,
1224 const double sigma_ )
1225{
1226 ExceptionInfo exceptionInfo;
1227 GetExceptionInfo( &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001228 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00001229 MagickCore::Image* newImage =
cristy05c0c9a2011-09-05 23:16:13 +00001230 GaussianBlurImage( image(), width_, sigma_, image()->bias, &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001231 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +00001232 replaceImage( newImage );
1233 throwException( exceptionInfo );
1234 (void) DestroyExceptionInfo( &exceptionInfo );
1235}
1236
cristyb32b90a2009-09-07 21:45:48 +00001237// Apply a color lookup table (Hald CLUT) to the image.
1238void Magick::Image::haldClut ( const Image &clutImage_ )
1239{
cristy7c0a0a42011-08-23 17:57:25 +00001240 ExceptionInfo exceptionInfo;
1241 GetExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +00001242 modifyImage();
cristy7c0a0a42011-08-23 17:57:25 +00001243 (void) HaldClutImage( image(), clutImage_.constImage(), &exceptionInfo );
1244 throwException( exceptionInfo );
1245 (void) DestroyExceptionInfo( &exceptionInfo );
cristyb32b90a2009-09-07 21:45:48 +00001246}
1247
cristy3ed852e2009-09-05 21:47:34 +00001248// Implode image
1249void Magick::Image::implode ( const double factor_ )
1250{
1251 ExceptionInfo exceptionInfo;
1252 GetExceptionInfo( &exceptionInfo );
1253 MagickCore::Image* newImage =
cristy76f512e2011-09-12 01:26:56 +00001254 ImplodeImage( image(), factor_, image()->interpolate, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001255 replaceImage( newImage );
1256 throwException( exceptionInfo );
1257 (void) DestroyExceptionInfo( &exceptionInfo );
1258}
1259
cristy529fcc22009-11-14 18:15:08 +00001260// implements the inverse discrete Fourier transform (IFT) of the image either
1261// as a magnitude / phase or real / imaginary image pair.
1262void Magick::Image::inverseFourierTransform ( const Image &phase_ )
1263{
1264 ExceptionInfo exceptionInfo;
1265 GetExceptionInfo( &exceptionInfo );
1266 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1267 phase_.constImage(), MagickTrue, &exceptionInfo);
1268 replaceImage( newImage );
1269 throwException( exceptionInfo );
1270 (void) DestroyExceptionInfo( &exceptionInfo );
1271}
1272void Magick::Image::inverseFourierTransform ( const Image &phase_,
1273 const bool magnitude_ )
1274{
1275 ExceptionInfo exceptionInfo;
1276 GetExceptionInfo( &exceptionInfo );
1277 MagickCore::Image* newImage = InverseFourierTransformImage( image(),
1278 phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
1279 &exceptionInfo);
1280 replaceImage( newImage );
1281 throwException( exceptionInfo );
1282 (void) DestroyExceptionInfo( &exceptionInfo );
1283}
1284
cristy3ed852e2009-09-05 21:47:34 +00001285// Level image. Adjust the levels of the image by scaling the colors
1286// falling between specified white and black points to the full
1287// available quantum range. The parameters provided represent the
1288// black, mid (gamma), and white points. The black point specifies
1289// the darkest color in the image. Colors darker than the black point
1290// are set to zero. Mid point (gamma) specifies a gamma correction to
1291// apply to the image. White point specifies the lightest color in the
1292// image. Colors brighter than the white point are set to the maximum
1293// quantum value. The black and white point have the valid range 0 to
1294// QuantumRange while gamma has a useful range of 0 to ten.
1295void Magick::Image::level ( const double black_point,
1296 const double white_point,
1297 const double gamma )
1298{
cristy01e9afd2011-08-10 17:38:41 +00001299 ExceptionInfo exceptionInfo;
1300 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001301 modifyImage();
cristy01e9afd2011-08-10 17:38:41 +00001302 (void) LevelImage( image(), black_point, white_point, gamma, &exceptionInfo );
1303 throwException( exceptionInfo );
1304 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001305}
1306
1307// Magnify image by integral size
1308void Magick::Image::magnify ( void )
1309{
1310 ExceptionInfo exceptionInfo;
1311 GetExceptionInfo( &exceptionInfo );
1312 MagickCore::Image* newImage =
1313 MagnifyImage( image(), &exceptionInfo );
1314 replaceImage( newImage );
1315 throwException( exceptionInfo );
1316 (void) DestroyExceptionInfo( &exceptionInfo );
1317}
1318
1319// Remap image colors with closest color from reference image
1320void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
1321{
cristy018f07f2011-09-04 21:15:19 +00001322 ExceptionInfo exceptionInfo;
1323 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001324 modifyImage();
1325 options()->quantizeDither( dither_ );
1326 RemapImage ( options()->quantizeInfo(), image(),
cristy018f07f2011-09-04 21:15:19 +00001327 mapImage_.constImage(), &exceptionInfo);
1328 throwException( exceptionInfo );
1329 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001330}
cristy4c08aed2011-07-01 19:47:50 +00001331// Floodfill designated area with replacement alpha value
cristy3ed852e2009-09-05 21:47:34 +00001332void Magick::Image::matteFloodfill ( const Color &target_ ,
cristy4c08aed2011-07-01 19:47:50 +00001333 const unsigned int alpha_,
cristyd99b0962010-05-29 23:14:26 +00001334 const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00001335 const Magick::PaintMethod method_ )
1336{
1337 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001338 PixelInfo target;
1339 GetPixelInfo(constImage(),&target);
cristy3ed852e2009-09-05 21:47:34 +00001340 target.red=static_cast<PixelPacket>(target_).red;
1341 target.green=static_cast<PixelPacket>(target_).green;
1342 target.blue=static_cast<PixelPacket>(target_).blue;
cristy4c08aed2011-07-01 19:47:50 +00001343 target.alpha=alpha_;
cristybd5a96c2011-08-21 00:04:26 +00001344 ChannelType channel_mask = SetPixelChannelMask( image(), AlphaChannel );
cristy189e84c2011-08-27 18:08:53 +00001345 ExceptionInfo exceptionInfo;
1346 GetExceptionInfo( &exceptionInfo );
cristyd42d9952011-07-08 14:21:50 +00001347 FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
cristy189e84c2011-08-27 18:08:53 +00001348 method_ == FloodfillMethod ? MagickFalse : MagickTrue, &exceptionInfo);
cristybd5a96c2011-08-21 00:04:26 +00001349 (void) SetPixelChannelMap( image(), channel_mask );
cristy189e84c2011-08-27 18:08:53 +00001350 throwException( exceptionInfo );
1351 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001352}
1353
1354// Filter image by replacing each pixel component with the median
1355// color in a circular neighborhood
1356void Magick::Image::medianFilter ( const double radius_ )
1357{
1358 ExceptionInfo exceptionInfo;
1359 GetExceptionInfo( &exceptionInfo );
1360 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001361 StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
1362 radius_,&exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001363 replaceImage( newImage );
1364 throwException( exceptionInfo );
1365 (void) DestroyExceptionInfo( &exceptionInfo );
1366}
1367
1368// Reduce image by integral size
1369void Magick::Image::minify ( void )
1370{
1371 ExceptionInfo exceptionInfo;
1372 GetExceptionInfo( &exceptionInfo );
1373 MagickCore::Image* newImage =
1374 MinifyImage( image(), &exceptionInfo );
1375 replaceImage( newImage );
1376 throwException( exceptionInfo );
1377 (void) DestroyExceptionInfo( &exceptionInfo );
1378}
1379
1380// Modulate percent hue, saturation, and brightness of an image
1381void Magick::Image::modulate ( const double brightness_,
1382 const double saturation_,
1383 const double hue_ )
1384{
1385 char modulate[MaxTextExtent + 1];
cristyb51dff52011-05-19 16:55:47 +00001386 FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
cristy3ed852e2009-09-05 21:47:34 +00001387 brightness_, saturation_, hue_);
1388
cristy33bd5152011-08-24 01:42:24 +00001389 ExceptionInfo exceptionInfo;
1390 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001391 modifyImage();
cristy33bd5152011-08-24 01:42:24 +00001392 ModulateImage( image(), modulate, &exceptionInfo );
1393 throwException( exceptionInfo );
1394 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001395}
1396
1397// Motion blur image with specified blur factor
1398// The radius_ parameter specifies the radius of the Gaussian, in
1399// pixels, not counting the center pixel. The sigma_ parameter
1400// specifies the standard deviation of the Laplacian, in pixels.
1401// The angle_ parameter specifies the angle the object appears
1402// to be comming from (zero degrees is from the right).
1403void Magick::Image::motionBlur ( const double radius_,
1404 const double sigma_,
1405 const double angle_ )
1406{
1407 ExceptionInfo exceptionInfo;
1408 GetExceptionInfo( &exceptionInfo );
1409 MagickCore::Image* newImage =
cristyf7ef0252011-09-09 14:50:06 +00001410 MotionBlurImage( image(), radius_, sigma_, angle_, 0.0, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00001411 replaceImage( newImage );
1412 throwException( exceptionInfo );
1413 (void) DestroyExceptionInfo( &exceptionInfo );
1414}
1415
1416// Negate image. Set grayscale_ to true to effect grayscale values
1417// only
1418void Magick::Image::negate ( const bool grayscale_ )
1419{
cristyb3e7c6c2011-07-24 01:43:55 +00001420 ExceptionInfo exceptionInfo;
1421 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001422 modifyImage();
cristyb3e7c6c2011-07-24 01:43:55 +00001423 NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse,
1424 &exceptionInfo );
1425 throwException( exceptionInfo );
1426 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001427}
1428
1429// Normalize image
1430void Magick::Image::normalize ( void )
1431{
1432 modifyImage();
cristye23ec9d2011-08-16 18:15:40 +00001433 ExceptionInfo exceptionInfo;
1434 GetExceptionInfo( &exceptionInfo );
1435 NormalizeImage ( image(), &exceptionInfo );
1436 throwException( exceptionInfo );
1437 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001438}
1439
1440// Oilpaint image
cristy14973ba2011-08-27 23:48:07 +00001441void Magick::Image::oilPaint ( const double radius_, const double sigma_ )
cristy3ed852e2009-09-05 21:47:34 +00001442{
1443 ExceptionInfo exceptionInfo;
1444 GetExceptionInfo( &exceptionInfo );
1445 MagickCore::Image* newImage =
cristy14973ba2011-08-27 23:48:07 +00001446 OilPaintImage( image(), radius_, sigma_, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001447 replaceImage( newImage );
1448 throwException( exceptionInfo );
1449 (void) DestroyExceptionInfo( &exceptionInfo );
1450}
1451
cristy4c08aed2011-07-01 19:47:50 +00001452// Set or attenuate the alpha channel. If the image pixels are
1453// opaque then they are set to the specified alpha value, otherwise
1454// they are blended with the supplied alpha value. The value of
1455// alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines
1456// OpaqueAlpha and TransparentAlpha are available to specify
cristy3ed852e2009-09-05 21:47:34 +00001457// completely opaque or completely transparent, respectively.
cristy4c08aed2011-07-01 19:47:50 +00001458void Magick::Image::alpha ( const unsigned int alpha_ )
cristy3ed852e2009-09-05 21:47:34 +00001459{
1460 modifyImage();
cristy4c08aed2011-07-01 19:47:50 +00001461 SetImageOpacity( image(), alpha_ );
cristy3ed852e2009-09-05 21:47:34 +00001462}
1463
1464// Change the color of an opaque pixel to the pen color.
1465void Magick::Image::opaque ( const Color &opaqueColor_,
1466 const Color &penColor_ )
1467{
1468 if ( !opaqueColor_.isValid() )
1469 {
1470 throwExceptionExplicit( OptionError,
1471 "Opaque color argument is invalid" );
1472 }
1473 if ( !penColor_.isValid() )
1474 {
1475 throwExceptionExplicit( OptionError,
1476 "Pen color argument is invalid" );
1477 }
1478
1479 modifyImage();
1480 std::string opaqueColor = opaqueColor_;
1481 std::string penColor = penColor_;
1482
cristy4c08aed2011-07-01 19:47:50 +00001483 PixelInfo opaque;
1484 PixelInfo pen;
cristy189e84c2011-08-27 18:08:53 +00001485 ExceptionInfo exceptionInfo;
1486 GetExceptionInfo( &exceptionInfo );
cristy9950d572011-10-01 18:22:35 +00001487 (void) QueryMagickColorCompliance(std::string(opaqueColor_).c_str(),
1488 AllCompliance, &opaque, &exceptionInfo);
1489 (void) QueryMagickColorCompliance(std::string(penColor_).c_str(),
1490 AllCompliance, &pen, &exceptionInfo);
cristy189e84c2011-08-27 18:08:53 +00001491 OpaquePaintImage ( image(), &opaque, &pen, MagickFalse, &exceptionInfo );
1492 throwException( exceptionInfo );
1493 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001494}
1495
1496// Ping is similar to read except only enough of the image is read to
1497// determine the image columns, rows, and filesize. Access the
1498// columns(), rows(), and fileSize() attributes after invoking ping.
1499// The image data is not valid after calling ping.
1500void Magick::Image::ping ( const std::string &imageSpec_ )
1501{
1502 options()->fileName( imageSpec_ );
1503 ExceptionInfo exceptionInfo;
1504 GetExceptionInfo( &exceptionInfo );
1505 MagickCore::Image* image =
1506 PingImage( imageInfo(), &exceptionInfo );
1507 replaceImage( image );
1508 throwException( exceptionInfo );
1509 (void) DestroyExceptionInfo( &exceptionInfo );
1510}
1511
1512// Ping is similar to read except only enough of the image is read
1513// to determine the image columns, rows, and filesize. Access the
1514// columns(), rows(), and fileSize() attributes after invoking
1515// ping. The image data is not valid after calling ping.
1516void Magick::Image::ping ( const Blob& blob_ )
1517{
1518 ExceptionInfo exceptionInfo;
1519 GetExceptionInfo( &exceptionInfo );
1520 MagickCore::Image* image =
1521 PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
1522 replaceImage( image );
1523 throwException( exceptionInfo );
1524 (void) DestroyExceptionInfo( &exceptionInfo );
1525}
1526
1527// Execute a named process module using an argc/argv syntax similar to
1528// that accepted by a C 'main' routine. An exception is thrown if the
1529// requested process module doesn't exist, fails to load, or fails during
1530// execution.
cristyd99b0962010-05-29 23:14:26 +00001531void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
cristy3ed852e2009-09-05 21:47:34 +00001532{
1533 modifyImage();
1534
cristyeaedf062010-05-29 22:36:02 +00001535 size_t status =
cristy3ed852e2009-09-05 21:47:34 +00001536 InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
1537 &image()->exception );
1538
1539 if (status == false)
1540 throwException( image()->exception );
1541}
1542
1543// Quantize colors in image using current quantization settings
1544// Set measureError_ to true in order to measure quantization error
1545void Magick::Image::quantize ( const bool measureError_ )
1546{
1547 modifyImage();
1548
1549 if (measureError_)
1550 options()->quantizeInfo()->measure_error=MagickTrue;
1551 else
1552 options()->quantizeInfo()->measure_error=MagickFalse;
1553
cristy018f07f2011-09-04 21:15:19 +00001554 ExceptionInfo exceptionInfo;
1555 GetExceptionInfo( &exceptionInfo );
1556 QuantizeImage( options()->quantizeInfo(), image(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001557
cristy018f07f2011-09-04 21:15:19 +00001558 throwException( exceptionInfo );
1559 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001560}
1561
1562// Apply an arithmetic or bitwise operator to the image pixel quantums.
1563void Magick::Image::quantumOperator ( const ChannelType channel_,
1564 const MagickEvaluateOperator operator_,
1565 double rvalue_)
1566{
1567 ExceptionInfo exceptionInfo;
1568 GetExceptionInfo( &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001569 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
cristyd42d9952011-07-08 14:21:50 +00001570 EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
cristybd5a96c2011-08-21 00:04:26 +00001571 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +00001572 throwException( exceptionInfo );
1573 (void) DestroyExceptionInfo( &exceptionInfo );
1574}
1575
cristyd99b0962010-05-29 23:14:26 +00001576void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00001577 const size_t columns_,
1578 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00001579 const ChannelType channel_,
1580 const MagickEvaluateOperator operator_,
1581 const double rvalue_)
1582{
1583 ExceptionInfo exceptionInfo;
1584 GetExceptionInfo( &exceptionInfo );
1585 RectangleInfo geometry;
1586 geometry.width = columns_;
1587 geometry.height = rows_;
1588 geometry.x = x_;
1589 geometry.y = y_;
1590 MagickCore::Image *crop_image = CropImage( image(), &geometry,
1591 &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001592 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
cristyd42d9952011-07-08 14:21:50 +00001593 EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001594 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +00001595 (void) CompositeImage( image(), image()->matte != MagickFalse ?
1596 OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
1597 crop_image = DestroyImageList(crop_image);
1598 throwException( exceptionInfo );
1599 (void) DestroyExceptionInfo( &exceptionInfo );
1600}
1601
1602// Raise image (lighten or darken the edges of an image to give a 3-D
1603// raised or lowered effect)
1604void Magick::Image::raise ( const Geometry &geometry_ ,
1605 const bool raisedFlag_ )
1606{
cristy6170ac32011-08-28 14:15:37 +00001607 ExceptionInfo exceptionInfo;
1608 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001609 RectangleInfo raiseInfo = geometry_;
1610 modifyImage();
cristy6170ac32011-08-28 14:15:37 +00001611 RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse, &exceptionInfo );
1612 throwException( exceptionInfo );
1613 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001614}
1615
1616
1617// Random threshold image.
1618//
1619// Changes the value of individual pixels based on the intensity
1620// of each pixel compared to a random threshold. The result is a
1621// low-contrast, two color image. The thresholds_ argument is a
1622// geometry containing LOWxHIGH thresholds. If the string
1623// contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
1624// 3, or 4 will be performed instead. If a channel_ argument is
1625// specified then only the specified channel is altered. This is
1626// a very fast alternative to 'quantize' based dithering.
1627void Magick::Image::randomThreshold( const Geometry &thresholds_ )
1628{
1629 randomThresholdChannel(thresholds_,DefaultChannels);
1630}
1631void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
1632 const ChannelType channel_ )
1633{
1634 ExceptionInfo exceptionInfo;
1635 GetExceptionInfo( &exceptionInfo );
1636 modifyImage();
cristybd5a96c2011-08-21 00:04:26 +00001637 ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
cristyf4ad9df2011-07-08 16:49:03 +00001638 (void) RandomThresholdImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00001639 static_cast<std::string>(thresholds_).c_str(),
1640 &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001641 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +00001642 throwImageException();
1643 (void) DestroyExceptionInfo( &exceptionInfo );
1644}
1645
1646// Read image into current object
1647void Magick::Image::read ( const std::string &imageSpec_ )
1648{
1649 options()->fileName( imageSpec_ );
1650
1651 ExceptionInfo exceptionInfo;
1652 GetExceptionInfo( &exceptionInfo );
1653 MagickCore::Image* image =
1654 ReadImage( imageInfo(), &exceptionInfo );
1655
1656 // Ensure that multiple image frames were not read.
1657 if ( image && image->next )
1658 {
1659 // Destroy any extra image frames
1660 MagickCore::Image* next = image->next;
1661 image->next = 0;
1662 next->previous = 0;
1663 DestroyImageList( next );
1664
1665 }
1666 replaceImage( image );
1667 throwException( exceptionInfo );
1668 if ( image )
1669 throwException( image->exception );
1670 (void) DestroyExceptionInfo( &exceptionInfo );
1671}
1672
1673// Read image of specified size into current object
1674void Magick::Image::read ( const Geometry &size_,
1675 const std::string &imageSpec_ )
1676{
1677 size( size_ );
1678 read( imageSpec_ );
1679}
1680
1681// Read image from in-memory BLOB
1682void Magick::Image::read ( const Blob &blob_ )
1683{
1684 ExceptionInfo exceptionInfo;
1685 GetExceptionInfo( &exceptionInfo );
1686 MagickCore::Image* image =
1687 BlobToImage( imageInfo(),
1688 static_cast<const void *>(blob_.data()),
1689 blob_.length(), &exceptionInfo );
1690 replaceImage( image );
1691 throwException( exceptionInfo );
1692 if ( image )
1693 throwException( image->exception );
1694 (void) DestroyExceptionInfo( &exceptionInfo );
1695}
1696
1697// Read image of specified size from in-memory BLOB
1698void Magick::Image::read ( const Blob &blob_,
1699 const Geometry &size_ )
1700{
1701 // Set image size
1702 size( size_ );
1703 // Read from Blob
1704 read( blob_ );
1705}
1706
1707// Read image of specified size and depth from in-memory BLOB
1708void Magick::Image::read ( const Blob &blob_,
1709 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001710 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00001711{
1712 // Set image size
1713 size( size_ );
1714 // Set image depth
1715 depth( depth_ );
1716 // Read from Blob
1717 read( blob_ );
1718}
1719
1720// Read image of specified size, depth, and format from in-memory BLOB
1721void Magick::Image::read ( const Blob &blob_,
1722 const Geometry &size_,
cristyeaedf062010-05-29 22:36:02 +00001723 const size_t depth_,
cristy3ed852e2009-09-05 21:47:34 +00001724 const std::string &magick_ )
1725{
1726 // Set image size
1727 size( size_ );
1728 // Set image depth
1729 depth( depth_ );
1730 // Set image magick
1731 magick( magick_ );
1732 // Set explicit image format
1733 fileName( magick_ + ':');
1734 // Read from Blob
1735 read( blob_ );
1736}
1737
1738// Read image of specified size, and format from in-memory BLOB
1739void Magick::Image::read ( const Blob &blob_,
1740 const Geometry &size_,
1741 const std::string &magick_ )
1742{
1743 // Set image size
1744 size( size_ );
1745 // Set image magick
1746 magick( magick_ );
1747 // Set explicit image format
1748 fileName( magick_ + ':');
1749 // Read from Blob
1750 read( blob_ );
1751}
1752
1753// Read image based on raw pixels in memory (ConstituteImage)
cristyeaedf062010-05-29 22:36:02 +00001754void Magick::Image::read ( const size_t width_,
1755 const size_t height_,
cristy3ed852e2009-09-05 21:47:34 +00001756 const std::string &map_,
1757 const StorageType type_,
1758 const void *pixels_ )
1759{
1760 ExceptionInfo exceptionInfo;
1761 GetExceptionInfo( &exceptionInfo );
1762 MagickCore::Image* image =
1763 ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
1764 &exceptionInfo );
1765 replaceImage( image );
1766 throwException( exceptionInfo );
1767 if ( image )
1768 throwException( image->exception );
1769 (void) DestroyExceptionInfo( &exceptionInfo );
1770}
1771
cristy3ed852e2009-09-05 21:47:34 +00001772// Reduce noise in image
1773void Magick::Image::reduceNoise ( const double order_ )
1774{
1775 ExceptionInfo exceptionInfo;
1776 GetExceptionInfo( &exceptionInfo );
1777 MagickCore::Image* newImage =
cristy95c38342011-03-18 22:39:51 +00001778 StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
1779 &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001780 replaceImage( newImage );
1781 throwException( exceptionInfo );
1782 (void) DestroyExceptionInfo( &exceptionInfo );
1783}
1784
1785// Resize image
1786void Magick::Image::resize( const Geometry &geometry_ )
1787{
1788 // Calculate new size. This code should be supported using binary arguments
1789 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00001790 ssize_t x = 0;
1791 ssize_t y = 0;
1792 size_t width = columns();
1793 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001794
1795 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1796 &x, &y,
1797 &width, &height );
1798
1799 ExceptionInfo exceptionInfo;
1800 GetExceptionInfo( &exceptionInfo );
1801 MagickCore::Image* newImage =
1802 ResizeImage( image(),
1803 width,
1804 height,
1805 image()->filter,
1806 1.0,
1807 &exceptionInfo);
1808 replaceImage( newImage );
1809 throwException( exceptionInfo );
1810 (void) DestroyExceptionInfo( &exceptionInfo );
1811}
1812
1813// Roll image
1814void Magick::Image::roll ( const Geometry &roll_ )
1815{
cristybb503372010-05-27 20:51:26 +00001816 ssize_t xOff = roll_.xOff();
cristy3ed852e2009-09-05 21:47:34 +00001817 if ( roll_.xNegative() )
1818 xOff = 0 - xOff;
cristybb503372010-05-27 20:51:26 +00001819 ssize_t yOff = roll_.yOff();
cristy3ed852e2009-09-05 21:47:34 +00001820 if ( roll_.yNegative() )
1821 yOff = 0 - yOff;
1822
1823 ExceptionInfo exceptionInfo;
1824 GetExceptionInfo( &exceptionInfo );
1825 MagickCore::Image* newImage =
1826 RollImage( image(), xOff, yOff, &exceptionInfo );
1827 replaceImage( newImage );
1828 throwException( exceptionInfo );
1829 (void) DestroyExceptionInfo( &exceptionInfo );
1830}
cristyeaedf062010-05-29 22:36:02 +00001831void Magick::Image::roll ( const size_t columns_,
1832 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00001833{
1834 ExceptionInfo exceptionInfo;
1835 GetExceptionInfo( &exceptionInfo );
1836 MagickCore::Image* newImage =
1837 RollImage( image(),
cristybb503372010-05-27 20:51:26 +00001838 static_cast<ssize_t>(columns_),
1839 static_cast<ssize_t>(rows_), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001840 replaceImage( newImage );
1841 throwException( exceptionInfo );
1842 (void) DestroyExceptionInfo( &exceptionInfo );
1843}
1844
1845// Rotate image
1846void Magick::Image::rotate ( const double degrees_ )
1847{
1848 ExceptionInfo exceptionInfo;
1849 GetExceptionInfo( &exceptionInfo );
1850 MagickCore::Image* newImage =
1851 RotateImage( image(), degrees_, &exceptionInfo);
1852 replaceImage( newImage );
1853 throwException( exceptionInfo );
1854 (void) DestroyExceptionInfo( &exceptionInfo );
1855}
1856
1857// Sample image
1858void Magick::Image::sample ( const Geometry &geometry_ )
1859{
cristybb503372010-05-27 20:51:26 +00001860 ssize_t x = 0;
1861 ssize_t y = 0;
1862 size_t width = columns();
1863 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001864
1865 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1866 &x, &y,
1867 &width, &height );
1868
1869 ExceptionInfo exceptionInfo;
1870 GetExceptionInfo( &exceptionInfo );
1871 MagickCore::Image* newImage =
1872 SampleImage( image(), width, height, &exceptionInfo );
1873 replaceImage( newImage );
1874 throwException( exceptionInfo );
1875 (void) DestroyExceptionInfo( &exceptionInfo );
1876}
1877
1878// Scale image
1879void Magick::Image::scale ( const Geometry &geometry_ )
1880{
cristybb503372010-05-27 20:51:26 +00001881 ssize_t x = 0;
1882 ssize_t y = 0;
1883 size_t width = columns();
1884 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00001885
1886 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
1887 &x, &y,
1888 &width, &height );
1889
1890 ExceptionInfo exceptionInfo;
1891 GetExceptionInfo( &exceptionInfo );
1892 MagickCore::Image* newImage =
1893 ScaleImage( image(), width, height, &exceptionInfo );
1894 replaceImage( newImage );
1895 throwException( exceptionInfo );
1896 (void) DestroyExceptionInfo( &exceptionInfo );
1897}
1898
1899// Segment (coalesce similar image components) by analyzing the
1900// histograms of the color components and identifying units that are
1901// homogeneous with the fuzzy c-means technique.
1902void Magick::Image::segment ( const double clusterThreshold_,
1903 const double smoothingThreshold_ )
1904{
cristy018f07f2011-09-04 21:15:19 +00001905 ExceptionInfo exceptionInfo;
1906 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001907 modifyImage();
1908 SegmentImage ( image(),
1909 options()->quantizeColorSpace(),
1910 (MagickBooleanType) options()->verbose(),
1911 clusterThreshold_,
cristy018f07f2011-09-04 21:15:19 +00001912 smoothingThreshold_, &exceptionInfo );
1913 throwException( exceptionInfo );
1914 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00001915 SyncImage( image() );
cristy3ed852e2009-09-05 21:47:34 +00001916}
1917
1918// Shade image using distant light source
1919void Magick::Image::shade ( const double azimuth_,
1920 const double elevation_,
1921 const bool colorShading_ )
1922{
1923 ExceptionInfo exceptionInfo;
1924 GetExceptionInfo( &exceptionInfo );
1925 MagickCore::Image* newImage =
1926 ShadeImage( image(),
1927 colorShading_ == true ? MagickTrue : MagickFalse,
1928 azimuth_,
1929 elevation_,
1930 &exceptionInfo);
1931 replaceImage( newImage );
1932 throwException( exceptionInfo );
1933 (void) DestroyExceptionInfo( &exceptionInfo );
1934}
1935
1936// Sharpen pixels in image
1937void Magick::Image::sharpen ( const double radius_, const double sigma_ )
1938{
1939 ExceptionInfo exceptionInfo;
1940 GetExceptionInfo( &exceptionInfo );
1941 MagickCore::Image* newImage =
1942 SharpenImage( image(),
1943 radius_,
1944 sigma_,
cristy05c0c9a2011-09-05 23:16:13 +00001945 image()->bias,
cristy3ed852e2009-09-05 21:47:34 +00001946 &exceptionInfo );
1947 replaceImage( newImage );
1948 throwException( exceptionInfo );
1949 (void) DestroyExceptionInfo( &exceptionInfo );
1950}
1951
1952void Magick::Image::sharpenChannel ( const ChannelType channel_,
1953 const double radius_, const double sigma_ )
1954{
1955 ExceptionInfo exceptionInfo;
1956 GetExceptionInfo( &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001957 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00001958 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +00001959 SharpenImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00001960 radius_,
1961 sigma_,
cristy05c0c9a2011-09-05 23:16:13 +00001962 image()->bias,
cristy3ed852e2009-09-05 21:47:34 +00001963 &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00001964 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +00001965 replaceImage( newImage );
1966 throwException( exceptionInfo );
1967 (void) DestroyExceptionInfo( &exceptionInfo );
1968}
1969
1970// Shave pixels from image edges.
1971void Magick::Image::shave ( const Geometry &geometry_ )
1972{
1973 RectangleInfo shaveInfo = geometry_;
1974 ExceptionInfo exceptionInfo;
1975 GetExceptionInfo( &exceptionInfo );
1976 MagickCore::Image* newImage =
1977 ShaveImage( image(),
1978 &shaveInfo,
1979 &exceptionInfo);
1980 replaceImage( newImage );
1981 throwException( exceptionInfo );
1982 (void) DestroyExceptionInfo( &exceptionInfo );
1983}
1984
1985// Shear image
1986void Magick::Image::shear ( const double xShearAngle_,
1987 const double yShearAngle_ )
1988{
1989 ExceptionInfo exceptionInfo;
1990 GetExceptionInfo( &exceptionInfo );
1991 MagickCore::Image* newImage =
1992 ShearImage( image(),
1993 xShearAngle_,
1994 yShearAngle_,
1995 &exceptionInfo );
1996 replaceImage( newImage );
1997 throwException( exceptionInfo );
1998 (void) DestroyExceptionInfo( &exceptionInfo );
1999}
2000
2001// Contrast image
cristyeaedf062010-05-29 22:36:02 +00002002void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
cristy3ed852e2009-09-05 21:47:34 +00002003{
cristy33bd5152011-08-24 01:42:24 +00002004 ExceptionInfo exceptionInfo;
2005 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002006 modifyImage();
cristy33bd5152011-08-24 01:42:24 +00002007 (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint, &exceptionInfo );
2008 throwException( exceptionInfo );
2009 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002010}
2011
2012// Solarize image (similar to effect seen when exposing a photographic
2013// film to light during the development process)
2014void Magick::Image::solarize ( const double factor_ )
2015{
cristy5cbc0162011-08-29 00:36:28 +00002016 ExceptionInfo exceptionInfo;
2017 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002018 modifyImage();
cristy5cbc0162011-08-29 00:36:28 +00002019 SolarizeImage ( image(), factor_, &exceptionInfo );
2020 throwException( exceptionInfo );
2021 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002022}
2023
2024// Sparse color image, given a set of coordinates, interpolates the colors
2025// found at those coordinates, across the whole image, using various methods.
2026//
2027void Magick::Image::sparseColor ( const ChannelType channel,
2028 const SparseColorMethod method,
cristybb503372010-05-27 20:51:26 +00002029 const size_t number_arguments,
cristy3ed852e2009-09-05 21:47:34 +00002030 const double *arguments )
2031{
2032 ExceptionInfo exceptionInfo;
2033 GetExceptionInfo( &exceptionInfo );
cristy3884f692011-07-08 18:00:18 +00002034
cristybd5a96c2011-08-21 00:04:26 +00002035 ChannelType channel_mask = SetPixelChannelMask( image(), channel );
cristy3884f692011-07-08 18:00:18 +00002036 MagickCore::Image* newImage = SparseColorImage ( image(), method,
cristy3ed852e2009-09-05 21:47:34 +00002037 number_arguments, arguments, &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00002038 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +00002039 replaceImage( newImage );
2040 throwException( exceptionInfo );
2041 (void) DestroyExceptionInfo( &exceptionInfo );
2042}
2043
2044// Spread pixels randomly within image by specified ammount
cristyeaedf062010-05-29 22:36:02 +00002045void Magick::Image::spread ( const size_t amount_ )
cristy3ed852e2009-09-05 21:47:34 +00002046{
2047 ExceptionInfo exceptionInfo;
2048 GetExceptionInfo( &exceptionInfo );
2049 MagickCore::Image* newImage =
2050 SpreadImage( image(),
2051 amount_,
cristy5c4e2582011-09-11 19:21:03 +00002052 image()->interpolate,
cristy3ed852e2009-09-05 21:47:34 +00002053 &exceptionInfo );
2054 replaceImage( newImage );
2055 throwException( exceptionInfo );
2056 (void) DestroyExceptionInfo( &exceptionInfo );
2057}
2058
2059// Add a digital watermark to the image (based on second image)
2060void Magick::Image::stegano ( const Image &watermark_ )
2061{
2062 ExceptionInfo exceptionInfo;
2063 GetExceptionInfo( &exceptionInfo );
2064 MagickCore::Image* newImage =
2065 SteganoImage( image(),
2066 watermark_.constImage(),
2067 &exceptionInfo);
2068 replaceImage( newImage );
2069 throwException( exceptionInfo );
2070 (void) DestroyExceptionInfo( &exceptionInfo );
2071}
2072
2073// Stereo image (left image is current image)
2074void Magick::Image::stereo ( const Image &rightImage_ )
2075{
2076 ExceptionInfo exceptionInfo;
2077 GetExceptionInfo( &exceptionInfo );
2078 MagickCore::Image* newImage =
2079 StereoImage( image(),
2080 rightImage_.constImage(),
2081 &exceptionInfo);
2082 replaceImage( newImage );
2083 throwException( exceptionInfo );
2084 (void) DestroyExceptionInfo( &exceptionInfo );
2085}
2086
2087// Swirl image
2088void Magick::Image::swirl ( const double degrees_ )
2089{
2090 ExceptionInfo exceptionInfo;
2091 GetExceptionInfo( &exceptionInfo );
2092 MagickCore::Image* newImage =
cristy76f512e2011-09-12 01:26:56 +00002093 SwirlImage( image(), degrees_, image()->interpolate,
cristy3ed852e2009-09-05 21:47:34 +00002094 &exceptionInfo);
2095 replaceImage( newImage );
2096 throwException( exceptionInfo );
2097 (void) DestroyExceptionInfo( &exceptionInfo );
2098}
2099
2100// Texture image
2101void Magick::Image::texture ( const Image &texture_ )
2102{
2103 modifyImage();
2104 TextureImage( image(), texture_.constImage() );
2105 throwImageException();
2106}
2107
2108// Threshold image
2109void Magick::Image::threshold ( const double threshold_ )
2110{
2111 modifyImage();
2112 BilevelImage( image(), threshold_ );
2113 throwImageException();
2114}
2115
2116// Transform image based on image geometry only
2117void Magick::Image::transform ( const Geometry &imageGeometry_ )
2118{
2119 modifyImage();
2120 TransformImage ( &(image()), 0,
2121 std::string(imageGeometry_).c_str() );
2122 throwImageException();
2123}
2124// Transform image based on image and crop geometries
2125void Magick::Image::transform ( const Geometry &imageGeometry_,
2126 const Geometry &cropGeometry_ )
2127{
2128 modifyImage();
2129 TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
2130 std::string(imageGeometry_).c_str() );
2131 throwImageException();
2132}
2133
2134// Add matte image to image, setting pixels matching color to transparent
2135void Magick::Image::transparent ( const Color &color_ )
2136{
2137 if ( !color_.isValid() )
2138 {
2139 throwExceptionExplicit( OptionError,
2140 "Color argument is invalid" );
2141 }
2142
2143 std::string color = color_;
2144
cristy4c08aed2011-07-01 19:47:50 +00002145 PixelInfo target;
cristy9950d572011-10-01 18:22:35 +00002146 (void) QueryMagickColorCompliance(std::string(color_).c_str(),AllCompliance,
2147 &target,&image()->exception);
cristy189e84c2011-08-27 18:08:53 +00002148 ExceptionInfo exceptionInfo;
2149 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002150 modifyImage();
cristy189e84c2011-08-27 18:08:53 +00002151 TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse,
2152 &exceptionInfo );
2153 throwException( exceptionInfo );
2154 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002155}
2156
2157// Add matte image to image, setting pixels matching color to transparent
2158void Magick::Image::transparentChroma(const Color &colorLow_,
2159 const Color &colorHigh_)
2160{
2161 if ( !colorLow_.isValid() || !colorHigh_.isValid() )
2162 {
2163 throwExceptionExplicit( OptionError,
2164 "Color argument is invalid" );
2165 }
2166
2167 std::string colorLow = colorLow_;
2168 std::string colorHigh = colorHigh_;
2169
cristy4c08aed2011-07-01 19:47:50 +00002170 PixelInfo targetLow;
2171 PixelInfo targetHigh;
cristy9950d572011-10-01 18:22:35 +00002172 (void) QueryMagickColorCompliance(std::string(colorLow_).c_str(),
2173 AllCompliance,&targetLow,&image()->exception);
2174 (void) QueryMagickColorCompliance(std::string(colorHigh_).c_str(),
2175 AllCompliance,&targetHigh,&image()->exception);
cristy189e84c2011-08-27 18:08:53 +00002176 ExceptionInfo exceptionInfo;
2177 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002178 modifyImage();
2179 TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
cristy189e84c2011-08-27 18:08:53 +00002180 TransparentAlpha, MagickFalse, &exceptionInfo );
2181 throwException( exceptionInfo );
2182 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002183}
2184
2185
2186// Trim edges that are the background color from the image
2187void Magick::Image::trim ( void )
2188{
2189 ExceptionInfo exceptionInfo;
2190 GetExceptionInfo( &exceptionInfo );
2191 MagickCore::Image* newImage =
2192 TrimImage( image(), &exceptionInfo);
2193 replaceImage( newImage );
2194 throwException( exceptionInfo );
2195 (void) DestroyExceptionInfo( &exceptionInfo );
2196}
2197
2198// Replace image with a sharpened version of the original image
2199// using the unsharp mask algorithm.
2200// radius_
2201// the radius of the Gaussian, in pixels, not counting the
2202// center pixel.
2203// sigma_
2204// the standard deviation of the Gaussian, in pixels.
2205// amount_
2206// the percentage of the difference between the original and
2207// the blur image that is added back into the original.
2208// threshold_
2209// the threshold in pixels needed to apply the diffence amount.
2210void Magick::Image::unsharpmask ( const double radius_,
2211 const double sigma_,
2212 const double amount_,
2213 const double threshold_ )
2214{
2215 ExceptionInfo exceptionInfo;
2216 GetExceptionInfo( &exceptionInfo );
2217 MagickCore::Image* newImage =
2218 UnsharpMaskImage( image(),
2219 radius_,
2220 sigma_,
2221 amount_,
2222 threshold_,
2223 &exceptionInfo );
2224 replaceImage( newImage );
2225 throwException( exceptionInfo );
2226 (void) DestroyExceptionInfo( &exceptionInfo );
2227}
2228
2229void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
2230 const double radius_,
2231 const double sigma_,
2232 const double amount_,
2233 const double threshold_ )
2234{
2235 ExceptionInfo exceptionInfo;
2236 GetExceptionInfo( &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00002237 ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
cristy3ed852e2009-09-05 21:47:34 +00002238 MagickCore::Image* newImage =
cristyf4ad9df2011-07-08 16:49:03 +00002239 UnsharpMaskImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00002240 radius_,
2241 sigma_,
2242 amount_,
2243 threshold_,
2244 &exceptionInfo );
cristybd5a96c2011-08-21 00:04:26 +00002245 (void) SetPixelChannelMap( image(), channel_mask );
cristy3ed852e2009-09-05 21:47:34 +00002246 replaceImage( newImage );
2247 throwException( exceptionInfo );
2248 (void) DestroyExceptionInfo( &exceptionInfo );
2249}
2250
2251// Map image pixels to a sine wave
2252void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
2253{
2254 ExceptionInfo exceptionInfo;
2255 GetExceptionInfo( &exceptionInfo );
2256 MagickCore::Image* newImage =
2257 WaveImage( image(),
2258 amplitude_,
2259 wavelength_,
cristy5c4e2582011-09-11 19:21:03 +00002260 image()->interpolate,
cristy3ed852e2009-09-05 21:47:34 +00002261 &exceptionInfo);
2262 replaceImage( newImage );
2263 throwException( exceptionInfo );
2264 (void) DestroyExceptionInfo( &exceptionInfo );
2265}
2266
2267// Write image to file
2268void Magick::Image::write( const std::string &imageSpec_ )
2269{
cristy6f9e0d32011-08-28 16:32:09 +00002270 ExceptionInfo exceptionInfo;
2271 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002272 modifyImage();
2273 fileName( imageSpec_ );
cristy6f9e0d32011-08-28 16:32:09 +00002274 WriteImage( imageInfo(), image(), &exceptionInfo );
2275 throwException( exceptionInfo );
2276 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002277}
2278
2279// Write image to in-memory BLOB
2280void Magick::Image::write ( Blob *blob_ )
2281{
2282 modifyImage();
2283 size_t length = 2048; // Efficient size for small images
2284 ExceptionInfo exceptionInfo;
2285 GetExceptionInfo( &exceptionInfo );
2286 void* data = ImageToBlob( imageInfo(),
2287 image(),
2288 &length,
2289 &exceptionInfo);
2290 throwException( exceptionInfo );
2291 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2292 throwImageException();
2293 (void) DestroyExceptionInfo( &exceptionInfo );
2294}
2295void Magick::Image::write ( Blob *blob_,
2296 const std::string &magick_ )
2297{
2298 modifyImage();
2299 magick(magick_);
2300 size_t length = 2048; // Efficient size for small images
2301 ExceptionInfo exceptionInfo;
2302 GetExceptionInfo( &exceptionInfo );
2303 void* data = ImageToBlob( imageInfo(),
2304 image(),
2305 &length,
2306 &exceptionInfo);
2307 throwException( exceptionInfo );
2308 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2309 throwImageException();
2310 (void) DestroyExceptionInfo( &exceptionInfo );
2311}
2312void Magick::Image::write ( Blob *blob_,
2313 const std::string &magick_,
cristyeaedf062010-05-29 22:36:02 +00002314 const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002315{
2316 modifyImage();
2317 magick(magick_);
2318 depth(depth_);
2319 size_t length = 2048; // Efficient size for small images
2320 ExceptionInfo exceptionInfo;
2321 GetExceptionInfo( &exceptionInfo );
2322 void* data = ImageToBlob( imageInfo(),
2323 image(),
2324 &length,
2325 &exceptionInfo);
2326 throwException( exceptionInfo );
2327 blob_->updateNoCopy( data, length, Blob::MallocAllocator );
2328 throwImageException();
2329 (void) DestroyExceptionInfo( &exceptionInfo );
2330}
2331
2332// Write image to an array of pixels with storage type specified
2333// by user (ExportImagePixels), e.g.
2334// image.write( 0, 0, 640, 1, "RGB", 0, pixels );
cristyd99b0962010-05-29 23:14:26 +00002335void Magick::Image::write ( const ssize_t x_,
2336 const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00002337 const size_t columns_,
2338 const size_t rows_,
cristy3ed852e2009-09-05 21:47:34 +00002339 const std::string &map_,
2340 const StorageType type_,
2341 void *pixels_ )
2342{
2343 ExceptionInfo exceptionInfo;
2344 GetExceptionInfo( &exceptionInfo );
2345 ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
2346 pixels_,
2347 &exceptionInfo);
2348 throwException( exceptionInfo );
2349 (void) DestroyExceptionInfo( &exceptionInfo );
2350}
2351
2352// Zoom image
2353void Magick::Image::zoom( const Geometry &geometry_ )
2354{
2355 // Calculate new size. This code should be supported using binary arguments
2356 // in the ImageMagick library.
cristybb503372010-05-27 20:51:26 +00002357 ssize_t x = 0;
2358 ssize_t y = 0;
2359 size_t width = columns();
2360 size_t height = rows();
cristy3ed852e2009-09-05 21:47:34 +00002361
2362 ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
2363 &x, &y,
2364 &width, &height );
2365
2366 ExceptionInfo exceptionInfo;
2367 GetExceptionInfo( &exceptionInfo );
2368 MagickCore::Image* newImage =
cristy391f1ce2010-09-09 17:23:28 +00002369 ResizeImage( image(),
cristy3ed852e2009-09-05 21:47:34 +00002370 width,
2371 height,
cristy391f1ce2010-09-09 17:23:28 +00002372 image()->filter,
2373 image()->blur,
cristy3ed852e2009-09-05 21:47:34 +00002374 &exceptionInfo);
2375 replaceImage( newImage );
2376 throwException( exceptionInfo );
2377 (void) DestroyExceptionInfo( &exceptionInfo );
2378}
2379
2380/*
2381 * Methods for setting image attributes
2382 *
2383 */
2384
2385// Join images into a single multi-image file
2386void Magick::Image::adjoin ( const bool flag_ )
2387{
2388 modifyImage();
2389 options()->adjoin( flag_ );
2390}
2391bool Magick::Image::adjoin ( void ) const
2392{
2393 return constOptions()->adjoin();
2394}
2395
2396// Remove pixel aliasing
2397void Magick::Image::antiAlias( const bool flag_ )
2398{
2399 modifyImage();
cristyeaedf062010-05-29 22:36:02 +00002400 options()->antiAlias( static_cast<size_t>(flag_) );
cristy3ed852e2009-09-05 21:47:34 +00002401}
2402bool Magick::Image::antiAlias( void )
2403{
2404 return static_cast<bool>( options()->antiAlias( ) );
2405}
2406
2407// Animation inter-frame delay
cristyeaedf062010-05-29 22:36:02 +00002408void Magick::Image::animationDelay ( const size_t delay_ )
cristy3ed852e2009-09-05 21:47:34 +00002409{
2410 modifyImage();
2411 image()->delay = delay_;
2412}
cristyeaedf062010-05-29 22:36:02 +00002413size_t Magick::Image::animationDelay ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002414{
2415 return constImage()->delay;
2416}
2417
2418// Number of iterations to play animation
cristyeaedf062010-05-29 22:36:02 +00002419void Magick::Image::animationIterations ( const size_t iterations_ )
cristy3ed852e2009-09-05 21:47:34 +00002420{
2421 modifyImage();
2422 image()->iterations = iterations_;
2423}
cristyeaedf062010-05-29 22:36:02 +00002424size_t Magick::Image::animationIterations ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002425{
2426 return constImage()->iterations;
2427}
2428
2429// Access/Update a named image attribute
2430void Magick::Image::attribute ( const std::string name_,
2431 const std::string value_ )
2432{
2433 modifyImage();
2434 SetImageProperty( image(), name_.c_str(), value_.c_str() );
2435}
2436std::string Magick::Image::attribute ( const std::string name_ )
2437{
2438 const char *value = GetImageProperty( constImage(), name_.c_str() );
2439
2440 if ( value )
2441 return std::string( value );
2442
2443 return std::string(); // Intentionally no exception
2444}
2445
2446// Background color
cristy391f1ce2010-09-09 17:23:28 +00002447void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002448{
2449 modifyImage();
2450
cristy391f1ce2010-09-09 17:23:28 +00002451 if ( backgroundColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002452 {
cristy391f1ce2010-09-09 17:23:28 +00002453 image()->background_color = backgroundColor_;
cristy3ed852e2009-09-05 21:47:34 +00002454 }
2455 else
2456 {
cristy391f1ce2010-09-09 17:23:28 +00002457 image()->background_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002458 }
2459
cristy391f1ce2010-09-09 17:23:28 +00002460 options()->backgroundColor( backgroundColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002461}
2462Magick::Color Magick::Image::backgroundColor ( void ) const
2463{
2464 return constOptions()->backgroundColor( );
2465}
2466
2467// Background fill texture
2468void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
2469{
2470 modifyImage();
2471 options()->backgroundTexture( backgroundTexture_ );
2472}
2473std::string Magick::Image::backgroundTexture ( void ) const
2474{
2475 return constOptions()->backgroundTexture( );
2476}
2477
2478// Original image columns
cristyeaedf062010-05-29 22:36:02 +00002479size_t Magick::Image::baseColumns ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002480{
2481 return constImage()->magick_columns;
2482}
2483
2484// Original image name
2485std::string Magick::Image::baseFilename ( void ) const
2486{
2487 return std::string(constImage()->magick_filename);
2488}
2489
2490// Original image rows
cristyeaedf062010-05-29 22:36:02 +00002491size_t Magick::Image::baseRows ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002492{
2493 return constImage()->magick_rows;
2494}
2495
2496// Border color
cristy391f1ce2010-09-09 17:23:28 +00002497void Magick::Image::borderColor ( const Color &borderColor_ )
cristy3ed852e2009-09-05 21:47:34 +00002498{
2499 modifyImage();
2500
cristy391f1ce2010-09-09 17:23:28 +00002501 if ( borderColor_.isValid() )
cristy3ed852e2009-09-05 21:47:34 +00002502 {
cristy391f1ce2010-09-09 17:23:28 +00002503 image()->border_color = borderColor_;
cristy3ed852e2009-09-05 21:47:34 +00002504 }
2505 else
2506 {
cristy391f1ce2010-09-09 17:23:28 +00002507 image()->border_color = Color();
cristy3ed852e2009-09-05 21:47:34 +00002508 }
2509
cristy391f1ce2010-09-09 17:23:28 +00002510 options()->borderColor( borderColor_ );
cristy3ed852e2009-09-05 21:47:34 +00002511}
2512Magick::Color Magick::Image::borderColor ( void ) const
2513{
2514 return constOptions()->borderColor( );
2515}
2516
2517// Return smallest bounding box enclosing non-border pixels. The
2518// current fuzz value is used when discriminating between pixels.
2519// This is the crop bounding box used by crop(Geometry(0,0));
2520Magick::Geometry Magick::Image::boundingBox ( void ) const
2521{
2522 ExceptionInfo exceptionInfo;
2523 GetExceptionInfo( &exceptionInfo );
2524 RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
2525 throwException( exceptionInfo );
2526 (void) DestroyExceptionInfo( &exceptionInfo );
2527 return Geometry( bbox );
2528}
2529
2530// Text bounding-box base color
2531void Magick::Image::boxColor ( const Color &boxColor_ )
2532{
2533 modifyImage();
2534 options()->boxColor( boxColor_ );
2535}
2536Magick::Color Magick::Image::boxColor ( void ) const
2537{
2538 return constOptions()->boxColor( );
2539}
2540
2541// Pixel cache threshold. Once this threshold is exceeded, all
2542// subsequent pixels cache operations are to/from disk.
2543// This setting is shared by all Image objects.
2544/* static */
cristyeaedf062010-05-29 22:36:02 +00002545void Magick::Image::cacheThreshold ( const size_t threshold_ )
cristy3ed852e2009-09-05 21:47:34 +00002546{
2547 SetMagickResourceLimit( MemoryResource, threshold_ );
2548}
2549
2550void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
2551{
2552 modifyImage();
2553 image()->chromaticity.blue_primary.x = x_;
2554 image()->chromaticity.blue_primary.y = y_;
2555}
2556void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
2557{
2558 *x_ = constImage()->chromaticity.blue_primary.x;
2559 *y_ = constImage()->chromaticity.blue_primary.y;
2560}
2561
2562void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
2563{
2564 modifyImage();
2565 image()->chromaticity.green_primary.x = x_;
2566 image()->chromaticity.green_primary.y = y_;
2567}
2568void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
2569{
2570 *x_ = constImage()->chromaticity.green_primary.x;
2571 *y_ = constImage()->chromaticity.green_primary.y;
2572}
2573
2574void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
2575{
2576 modifyImage();
2577 image()->chromaticity.red_primary.x = x_;
2578 image()->chromaticity.red_primary.y = y_;
2579}
2580void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
2581{
2582 *x_ = constImage()->chromaticity.red_primary.x;
2583 *y_ = constImage()->chromaticity.red_primary.y;
2584}
2585
2586void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
2587{
2588 modifyImage();
2589 image()->chromaticity.white_point.x = x_;
2590 image()->chromaticity.white_point.y = y_;
2591}
2592void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
2593{
2594 *x_ = constImage()->chromaticity.white_point.x;
2595 *y_ = constImage()->chromaticity.white_point.y;
2596}
2597
2598// Set image storage class
2599void Magick::Image::classType ( const ClassType class_ )
2600{
2601 if ( classType() == PseudoClass && class_ == DirectClass )
2602 {
2603 // Use SyncImage to synchronize the DirectClass pixels with the
2604 // color map and then set to DirectClass type.
2605 modifyImage();
2606 SyncImage( image() );
2607 image()->colormap = (PixelPacket *)
2608 RelinquishMagickMemory( image()->colormap );
2609 image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
2610 return;
2611 }
2612
2613 if ( classType() == DirectClass && class_ == PseudoClass )
2614 {
2615 // Quantize to create PseudoClass color map
2616 modifyImage();
cristye6bbc092010-05-12 17:00:47 +00002617 quantizeColors(MaxColormapSize);
cristy3ed852e2009-09-05 21:47:34 +00002618 quantize();
2619 image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
2620 }
2621}
2622
2623// Associate a clip mask with the image. The clip mask must be the
2624// same dimensions as the image. Pass an invalid image to unset an
2625// existing clip mask.
2626void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
2627{
2628 modifyImage();
2629
cristy018f07f2011-09-04 21:15:19 +00002630 ExceptionInfo exceptionInfo;
2631 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002632 if( clipMask_.isValid() )
2633 {
2634 // Set clip mask
cristy018f07f2011-09-04 21:15:19 +00002635 SetImageClipMask( image(), clipMask_.constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002636 }
2637 else
2638 {
2639 // Unset existing clip mask
cristy018f07f2011-09-04 21:15:19 +00002640 SetImageClipMask( image(), 0, &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002641 }
cristy018f07f2011-09-04 21:15:19 +00002642 throwException( exceptionInfo );
2643 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00002644}
2645Magick::Image Magick::Image::clipMask ( void ) const
2646{
cristy018f07f2011-09-04 21:15:19 +00002647 ExceptionInfo exceptionInfo;
2648 GetExceptionInfo( &exceptionInfo );
2649 MagickCore::Image* image =
2650 GetImageClipMask( constImage(), &exceptionInfo );
2651 throwException( exceptionInfo );
2652 (void) DestroyExceptionInfo( &exceptionInfo );
2653 return Magick::Image( image );
cristy3ed852e2009-09-05 21:47:34 +00002654}
2655
2656void Magick::Image::colorFuzz ( const double fuzz_ )
2657{
2658 modifyImage();
2659 image()->fuzz = fuzz_;
2660 options()->colorFuzz( fuzz_ );
2661}
2662double Magick::Image::colorFuzz ( void ) const
2663{
2664 return constOptions()->colorFuzz( );
2665}
2666
2667// Set color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002668void Magick::Image::colorMap ( const size_t index_,
cristy3ed852e2009-09-05 21:47:34 +00002669 const Color &color_ )
2670{
2671 MagickCore::Image* imageptr = image();
2672
2673 if (index_ > (MaxColormapSize-1) )
2674 throwExceptionExplicit( OptionError,
2675 "Colormap index must be less than MaxColormapSize" );
2676
2677 if ( !color_.isValid() )
2678 throwExceptionExplicit( OptionError,
2679 "Color argument is invalid");
2680 modifyImage();
2681
2682 // Ensure that colormap size is large enough
2683 if ( colorMapSize() < (index_+1) )
2684 colorMapSize( index_ + 1 );
2685
2686 // Set color at index in colormap
2687 (imageptr->colormap)[index_] = color_;
2688}
2689// Return color in colormap at index
cristyeaedf062010-05-29 22:36:02 +00002690Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
cristy3ed852e2009-09-05 21:47:34 +00002691{
2692 const MagickCore::Image* imageptr = constImage();
2693
2694 if ( !imageptr->colormap )
2695 throwExceptionExplicit( OptionError,
2696 "Image does not contain a colormap");
2697
2698 if ( index_ > imageptr->colors-1 )
2699 throwExceptionExplicit( OptionError,
2700 "Index out of range");
2701
2702 return Magick::Color( (imageptr->colormap)[index_] );
2703}
2704
2705// Colormap size (number of colormap entries)
cristyeaedf062010-05-29 22:36:02 +00002706void Magick::Image::colorMapSize ( const size_t entries_ )
cristy3ed852e2009-09-05 21:47:34 +00002707{
2708 if (entries_ >MaxColormapSize )
2709 throwExceptionExplicit( OptionError,
2710 "Colormap entries must not exceed MaxColormapSize" );
2711
2712 modifyImage();
2713
2714 MagickCore::Image* imageptr = image();
2715
2716 if( !imageptr->colormap )
2717 {
2718 // Allocate colormap
2719 imageptr->colormap =
2720 static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
2721 imageptr->colors = 0;
2722 }
2723 else if ( entries_ > imageptr->colors )
2724 {
2725 // Re-allocate colormap
2726 imageptr->colormap=(PixelPacket *)
2727 ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
2728 }
2729
2730 // Initialize any new colormap entries as all black
2731 Color black(0,0,0);
cristyeaedf062010-05-29 22:36:02 +00002732 for( size_t i=imageptr->colors; i<(entries_-1); i++ )
cristy3ed852e2009-09-05 21:47:34 +00002733 (imageptr->colormap)[i] = black;
2734
2735 imageptr->colors = entries_;
2736}
cristyeaedf062010-05-29 22:36:02 +00002737size_t Magick::Image::colorMapSize ( void )
cristy3ed852e2009-09-05 21:47:34 +00002738{
2739 const MagickCore::Image* imageptr = constImage();
2740
2741 if ( !imageptr->colormap )
2742 throwExceptionExplicit( OptionError,
2743 "Image does not contain a colormap");
2744
2745 return imageptr->colors;
2746}
2747
2748// Image colorspace
2749void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
2750{
2751 // Nothing to do?
2752 if ( image()->colorspace == colorSpace_ )
2753 return;
2754
2755 modifyImage();
2756
2757 if ( colorSpace_ != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002758 colorSpace_ != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002759 colorSpace_ != TransparentColorspace &&
2760 colorSpace_ != GRAYColorspace )
2761 {
2762 if (image()->colorspace != RGBColorspace &&
cristy510d06a2011-07-06 23:43:54 +00002763 image()->colorspace != sRGBColorspace &&
cristy3ed852e2009-09-05 21:47:34 +00002764 image()->colorspace != TransparentColorspace &&
2765 image()->colorspace != GRAYColorspace)
2766 {
2767 /* Transform to RGB colorspace as intermediate step */
2768 TransformRGBImage( image(), image()->colorspace );
2769 throwImageException();
2770 }
2771 /* Transform to final non-RGB colorspace */
2772 RGBTransformImage( image(), colorSpace_ );
2773 throwImageException();
2774 return;
2775 }
2776
2777 if ( colorSpace_ == RGBColorspace ||
cristy510d06a2011-07-06 23:43:54 +00002778 colorSpace_ == sRGBColorspace ||
cristy3ed852e2009-09-05 21:47:34 +00002779 colorSpace_ == TransparentColorspace ||
2780 colorSpace_ == GRAYColorspace )
2781 {
2782 /* Transform to a RGB-type colorspace */
2783 TransformRGBImage( image(), image()->colorspace );
2784 throwImageException();
2785 return;
2786 }
2787}
2788Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
2789{
2790 return constImage()->colorspace;
2791}
2792
2793// Set image colorspace type.
2794void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
2795{
2796 modifyImage();
2797 options()->colorspaceType( colorSpace_ );
2798}
2799Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
2800{
2801 return constOptions()->colorspaceType();
2802}
2803
2804
2805// Comment string
2806void Magick::Image::comment ( const std::string &comment_ )
2807{
2808 modifyImage();
2809 SetImageProperty( image(), "Comment", NULL );
2810 if ( comment_.length() > 0 )
2811 SetImageProperty( image(), "Comment", comment_.c_str() );
2812 throwImageException();
2813}
2814std::string Magick::Image::comment ( void ) const
2815{
2816 const char *value = GetImageProperty( constImage(), "Comment" );
2817
2818 if ( value )
2819 return std::string( value );
2820
2821 return std::string(); // Intentionally no exception
2822}
2823
2824// Composition operator to be used when composition is implicitly used
2825// (such as for image flattening).
2826void Magick::Image::compose (const CompositeOperator compose_)
2827{
2828 image()->compose=compose_;
2829}
2830
2831Magick::CompositeOperator Magick::Image::compose ( void ) const
2832{
2833 return constImage()->compose;
2834}
2835
2836// Compression algorithm
2837void Magick::Image::compressType ( const CompressionType compressType_ )
2838{
2839 modifyImage();
2840 image()->compression = compressType_;
2841 options()->compressType( compressType_ );
2842}
2843Magick::CompressionType Magick::Image::compressType ( void ) const
2844{
2845 return constImage()->compression;
2846}
2847
2848// Enable printing of debug messages from ImageMagick
2849void Magick::Image::debug ( const bool flag_ )
2850{
2851 modifyImage();
2852 options()->debug( flag_ );
2853}
2854bool Magick::Image::debug ( void ) const
2855{
2856 return constOptions()->debug();
2857}
2858
2859// Tagged image format define (set/access coder-specific option) The
2860// magick_ option specifies the coder the define applies to. The key_
2861// option provides the key specific to that coder. The value_ option
2862// provides the value to set (if any). See the defineSet() method if the
2863// key must be removed entirely.
2864void Magick::Image::defineValue ( const std::string &magick_,
2865 const std::string &key_,
2866 const std::string &value_ )
2867{
2868 modifyImage();
2869 std::string format = magick_ + ":" + key_;
2870 std::string option = value_;
2871 (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
2872}
2873std::string Magick::Image::defineValue ( const std::string &magick_,
2874 const std::string &key_ ) const
2875{
2876 std::string definition = magick_ + ":" + key_;
2877 const char *option =
2878 GetImageOption ( constImageInfo(), definition.c_str() );
2879 if (option)
2880 return std::string( option );
2881 return std::string( );
2882}
2883
2884// Tagged image format define. Similar to the defineValue() method
2885// except that passing the flag_ value 'true' creates a value-less
2886// define with that format and key. Passing the flag_ value 'false'
2887// removes any existing matching definition. The method returns 'true'
2888// if a matching key exists, and 'false' if no matching key exists.
2889void Magick::Image::defineSet ( const std::string &magick_,
2890 const std::string &key_,
2891 bool flag_ )
2892{
2893 modifyImage();
2894 std::string definition = magick_ + ":" + key_;
2895 if (flag_)
2896 {
2897 (void) SetImageOption ( imageInfo(), definition.c_str(), "" );
2898 }
2899 else
2900 {
2901 DeleteImageOption( imageInfo(), definition.c_str() );
2902 }
2903}
2904bool Magick::Image::defineSet ( const std::string &magick_,
2905 const std::string &key_ ) const
2906{
2907 std::string key = magick_ + ":" + key_;
2908 const char *option =
2909 GetImageOption ( constImageInfo(), key.c_str() );
2910 if (option)
2911 return true;
2912 return false;
2913}
2914
2915// Pixel resolution
2916void Magick::Image::density ( const Geometry &density_ )
2917{
2918 modifyImage();
2919 options()->density( density_ );
2920 if ( density_.isValid() )
2921 {
2922 image()->x_resolution = density_.width();
2923 if ( density_.height() != 0 )
2924 {
2925 image()->y_resolution = density_.height();
2926 }
2927 else
2928 {
2929 image()->y_resolution = density_.width();
2930 }
2931 }
2932 else
2933 {
2934 // Reset to default
2935 image()->x_resolution = 0;
2936 image()->y_resolution = 0;
2937 }
2938}
2939Magick::Geometry Magick::Image::density ( void ) const
2940{
2941 if (isValid())
2942 {
cristy35ef8242010-06-03 16:24:13 +00002943 ssize_t x_resolution=72;
2944 ssize_t y_resolution=72;
cristy3ed852e2009-09-05 21:47:34 +00002945
2946 if (constImage()->x_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002947 x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002948
2949 if (constImage()->y_resolution > 0.0)
cristy9e7ec532010-06-03 18:40:45 +00002950 y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
cristy3ed852e2009-09-05 21:47:34 +00002951
2952 return Geometry(x_resolution,y_resolution);
2953 }
2954
2955 return constOptions()->density( );
2956}
2957
2958// Image depth (bits allocated to red/green/blue components)
cristyeaedf062010-05-29 22:36:02 +00002959void Magick::Image::depth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00002960{
cristyeaedf062010-05-29 22:36:02 +00002961 size_t depth = depth_;
cristy3ed852e2009-09-05 21:47:34 +00002962
2963 if (depth > MAGICKCORE_QUANTUM_DEPTH)
2964 depth=MAGICKCORE_QUANTUM_DEPTH;
2965
2966 modifyImage();
2967 image()->depth=depth;
2968 options()->depth( depth );
2969}
cristyeaedf062010-05-29 22:36:02 +00002970size_t Magick::Image::depth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00002971{
2972 return constImage()->depth;
2973}
2974
2975std::string Magick::Image::directory ( void ) const
2976{
2977 if ( constImage()->directory )
2978 return std::string( constImage()->directory );
2979
2980 throwExceptionExplicit( CorruptImageWarning,
2981 "Image does not contain a directory");
2982
2983 return std::string();
2984}
2985
2986// Endianness (little like Intel or big like SPARC) for image
2987// formats which support endian-specific options.
2988void Magick::Image::endian ( const Magick::EndianType endian_ )
2989{
2990 modifyImage();
2991 options()->endian( endian_ );
2992 image()->endian = endian_;
2993}
2994Magick::EndianType Magick::Image::endian ( void ) const
2995{
2996 return constImage()->endian;
2997}
2998
2999// EXIF profile (BLOB)
3000void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
3001{
3002 modifyImage();
3003 if ( exifProfile_.data() != 0 )
3004 {
3005 StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
3006 SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
3007 (void) SetImageProfile( image(), "exif", exif_profile);
3008 exif_profile =DestroyStringInfo( exif_profile );
3009 }
3010}
3011Magick::Blob Magick::Image::exifProfile( void ) const
3012{
3013 const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
3014 if ( exif_profile == (StringInfo *) NULL)
3015 return Blob( 0, 0 );
3016 return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
3017}
3018
3019// Image file name
3020void Magick::Image::fileName ( const std::string &fileName_ )
3021{
3022 modifyImage();
3023
3024 fileName_.copy( image()->filename,
3025 sizeof(image()->filename) - 1 );
3026 image()->filename[ fileName_.length() ] = 0; // Null terminate
3027
3028 options()->fileName( fileName_ );
3029
3030}
3031std::string Magick::Image::fileName ( void ) const
3032{
3033 return constOptions()->fileName( );
3034}
3035
3036// Image file size
3037off_t Magick::Image::fileSize ( void ) const
3038{
3039 return (off_t) GetBlobSize( constImage() );
3040}
3041
3042// Color to use when drawing inside an object
3043void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
3044{
3045 modifyImage();
3046 options()->fillColor(fillColor_);
3047}
3048Magick::Color Magick::Image::fillColor ( void ) const
3049{
3050 return constOptions()->fillColor();
3051}
3052
3053// Rule to use when filling drawn objects
3054void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
3055{
3056 modifyImage();
3057 options()->fillRule(fillRule_);
3058}
3059Magick::FillRule Magick::Image::fillRule ( void ) const
3060{
3061 return constOptions()->fillRule();
3062}
3063
3064// Pattern to use while filling drawn objects.
3065void Magick::Image::fillPattern ( const Image &fillPattern_ )
3066{
3067 modifyImage();
3068 if(fillPattern_.isValid())
3069 options()->fillPattern( fillPattern_.constImage() );
3070 else
3071 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3072}
3073Magick::Image Magick::Image::fillPattern ( void ) const
3074{
3075 // FIXME: This is inordinately innefficient
3076 Image texture;
3077
3078 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3079
3080 if ( tmpTexture )
3081 {
3082 ExceptionInfo exceptionInfo;
3083 GetExceptionInfo( &exceptionInfo );
3084 MagickCore::Image* image =
3085 CloneImage( tmpTexture,
3086 0, // columns
3087 0, // rows
3088 MagickTrue, // orphan
3089 &exceptionInfo);
3090 texture.replaceImage( image );
3091 throwException( exceptionInfo );
3092 (void) DestroyExceptionInfo( &exceptionInfo );
3093 }
3094 return texture;
3095}
3096
3097// Filter used by zoom
3098void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
3099{
3100 modifyImage();
3101 image()->filter = filterType_;
3102}
3103Magick::FilterTypes Magick::Image::filterType ( void ) const
3104{
3105 return constImage()->filter;
3106}
3107
3108// Font name
3109void Magick::Image::font ( const std::string &font_ )
3110{
3111 modifyImage();
3112 options()->font( font_ );
3113}
3114std::string Magick::Image::font ( void ) const
3115{
3116 return constOptions()->font( );
3117}
3118
3119// Font point size
3120void Magick::Image::fontPointsize ( const double pointSize_ )
3121{
3122 modifyImage();
3123 options()->fontPointsize( pointSize_ );
3124}
3125double Magick::Image::fontPointsize ( void ) const
3126{
3127 return constOptions()->fontPointsize( );
3128}
3129
3130// Font type metrics
3131void Magick::Image::fontTypeMetrics( const std::string &text_,
3132 TypeMetric *metrics )
3133{
3134 DrawInfo *drawInfo = options()->drawInfo();
3135 drawInfo->text = const_cast<char *>(text_.c_str());
cristy5cbc0162011-08-29 00:36:28 +00003136 ExceptionInfo exceptionInfo;
3137 GetExceptionInfo( &exceptionInfo );
3138 GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003139 drawInfo->text = 0;
cristy5cbc0162011-08-29 00:36:28 +00003140 throwException( exceptionInfo );
3141 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003142}
3143
3144// Image format string
3145std::string Magick::Image::format ( void ) const
3146{
3147 ExceptionInfo exceptionInfo;
3148 GetExceptionInfo( &exceptionInfo );
3149 const MagickInfo * magick_info
3150 = GetMagickInfo( constImage()->magick, &exceptionInfo);
3151 throwException( exceptionInfo );
3152 (void) DestroyExceptionInfo( &exceptionInfo );
3153
3154 if (( magick_info != 0 ) &&
3155 ( *magick_info->description != '\0' ))
3156 return std::string(magick_info->description);
3157
3158 throwExceptionExplicit( CorruptImageWarning,
3159 "Unrecognized image magick type" );
3160 return std::string();
3161}
3162
3163// Gamma adjustment
3164double Magick::Image::gamma ( void ) const
3165{
3166 return constImage()->gamma;
3167}
3168
3169Magick::Geometry Magick::Image::geometry ( void ) const
3170{
3171 if ( constImage()->geometry )
3172 {
3173 return Geometry(constImage()->geometry);
3174 }
3175
3176 throwExceptionExplicit( OptionWarning,
3177 "Image does not contain a geometry");
3178
3179 return Geometry();
3180}
3181
cristyeaedf062010-05-29 22:36:02 +00003182void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
cristy3ed852e2009-09-05 21:47:34 +00003183{
3184 modifyImage();
3185 image()->dispose = (DisposeType) disposeMethod_;
3186}
cristyeaedf062010-05-29 22:36:02 +00003187size_t Magick::Image::gifDisposeMethod ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003188{
3189 // FIXME: It would be better to return an enumeration
3190 return constImage()->dispose;
3191}
3192
3193// ICC ICM color profile (BLOB)
3194void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
3195{
3196 profile("icm",colorProfile_);
3197}
3198Magick::Blob Magick::Image::iccColorProfile( void ) const
3199{
3200 const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
3201 if ( color_profile == (StringInfo *) NULL)
3202 return Blob( 0, 0 );
3203 return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
3204}
3205
3206void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
3207{
3208 modifyImage();
3209 image()->interlace = interlace_;
3210 options()->interlaceType ( interlace_ );
3211}
3212Magick::InterlaceType Magick::Image::interlaceType ( void ) const
3213{
3214 return constImage()->interlace;
3215}
3216
3217// IPTC profile (BLOB)
3218void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
3219{
3220 modifyImage();
3221 if ( iptcProfile_.data() != 0 )
3222 {
3223 StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
3224 SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
3225 (void) SetImageProfile( image(), "iptc", iptc_profile);
3226 iptc_profile =DestroyStringInfo( iptc_profile );
3227 }
3228}
3229Magick::Blob Magick::Image::iptcProfile( void ) const
3230{
3231 const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
3232 if ( iptc_profile == (StringInfo *) NULL)
3233 return Blob( 0, 0 );
3234 return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
3235}
3236
3237// Does object contain valid image?
3238void Magick::Image::isValid ( const bool isValid_ )
3239{
3240 if ( !isValid_ )
3241 {
3242 delete _imgRef;
3243 _imgRef = new ImageRef;
3244 }
3245 else if ( !isValid() )
3246 {
3247 // Construct with single-pixel black image to make
3248 // image valid. This is an obvious hack.
3249 size( Geometry(1,1) );
3250 read( "xc:#000000" );
3251 }
3252}
3253
3254bool Magick::Image::isValid ( void ) const
3255{
3256 if ( rows() && columns() )
3257 return true;
3258
3259 return false;
3260}
3261
3262// Label image
3263void Magick::Image::label ( const std::string &label_ )
3264{
3265 modifyImage();
3266 SetImageProperty ( image(), "Label", NULL );
3267 if ( label_.length() > 0 )
3268 SetImageProperty ( image(), "Label", label_.c_str() );
3269 throwImageException();
3270}
3271std::string Magick::Image::label ( void ) const
3272{
3273 const char *value = GetImageProperty( constImage(), "Label" );
3274
3275 if ( value )
3276 return std::string( value );
3277
3278 return std::string();
3279}
3280
3281void Magick::Image::magick ( const std::string &magick_ )
3282{
3283 modifyImage();
3284
3285 magick_.copy( image()->magick,
3286 sizeof(image()->magick) - 1 );
3287 image()->magick[ magick_.length() ] = 0;
3288
3289 options()->magick( magick_ );
3290}
3291std::string Magick::Image::magick ( void ) const
3292{
3293 if ( *(constImage()->magick) != '\0' )
3294 return std::string(constImage()->magick);
3295
3296 return constOptions()->magick( );
3297}
3298
3299void Magick::Image::matte ( const bool matteFlag_ )
3300{
3301 modifyImage();
3302
3303 // If matte channel is requested, but image doesn't already have a
3304 // matte channel, then create an opaque matte channel. Likewise, if
3305 // the image already has a matte channel but a matte channel is not
3306 // desired, then set the matte channel to opaque.
3307 if ((matteFlag_ && !constImage()->matte) ||
3308 (constImage()->matte && !matteFlag_))
cristy4c08aed2011-07-01 19:47:50 +00003309 SetImageOpacity(image(),OpaqueAlpha);
cristy3ed852e2009-09-05 21:47:34 +00003310
3311 image()->matte = (MagickBooleanType) matteFlag_;
3312}
3313bool Magick::Image::matte ( void ) const
3314{
3315 if ( constImage()->matte )
3316 return true;
3317 else
3318 return false;
3319}
3320
3321void Magick::Image::matteColor ( const Color &matteColor_ )
3322{
3323 modifyImage();
3324
3325 if ( matteColor_.isValid() )
3326 {
cristy391f1ce2010-09-09 17:23:28 +00003327 image()->matte_color = matteColor_;
3328 options()->matteColor( matteColor_ );
cristy3ed852e2009-09-05 21:47:34 +00003329 }
3330 else
3331 {
3332 // Set to default matte color
3333 Color tmpColor( "#BDBDBD" );
cristy391f1ce2010-09-09 17:23:28 +00003334 image()->matte_color = tmpColor;
cristy3ed852e2009-09-05 21:47:34 +00003335 options()->matteColor( tmpColor );
3336 }
3337}
3338Magick::Color Magick::Image::matteColor ( void ) const
3339{
3340 return Color( constImage()->matte_color.red,
3341 constImage()->matte_color.green,
cristy391f1ce2010-09-09 17:23:28 +00003342 constImage()->matte_color.blue );
cristy3ed852e2009-09-05 21:47:34 +00003343}
3344
3345double Magick::Image::meanErrorPerPixel ( void ) const
3346{
3347 return(constImage()->error.mean_error_per_pixel);
3348}
3349
3350// Image modulus depth (minimum number of bits required to support
3351// red/green/blue components without loss of accuracy)
cristyeaedf062010-05-29 22:36:02 +00003352void Magick::Image::modulusDepth ( const size_t depth_ )
cristy3ed852e2009-09-05 21:47:34 +00003353{
3354 modifyImage();
3355 SetImageDepth( image(), depth_ );
3356 options()->depth( depth_ );
3357}
cristyeaedf062010-05-29 22:36:02 +00003358size_t Magick::Image::modulusDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003359{
3360 ExceptionInfo exceptionInfo;
3361 GetExceptionInfo( &exceptionInfo );
cristyeaedf062010-05-29 22:36:02 +00003362 size_t depth=GetImageDepth( constImage(), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003363 throwException( exceptionInfo );
3364 (void) DestroyExceptionInfo( &exceptionInfo );
3365 return depth;
3366}
3367
3368void Magick::Image::monochrome ( const bool monochromeFlag_ )
3369{
3370 modifyImage();
3371 options()->monochrome( monochromeFlag_ );
3372}
3373bool Magick::Image::monochrome ( void ) const
3374{
3375 return constOptions()->monochrome( );
3376}
3377
3378Magick::Geometry Magick::Image::montageGeometry ( void ) const
3379{
3380 if ( constImage()->montage )
3381 return Magick::Geometry(constImage()->montage);
3382
3383 throwExceptionExplicit( CorruptImageWarning,
3384 "Image does not contain a montage" );
3385
3386 return Magick::Geometry();
3387}
3388
3389double Magick::Image::normalizedMaxError ( void ) const
3390{
3391 return(constImage()->error.normalized_maximum_error);
3392}
3393
3394double Magick::Image::normalizedMeanError ( void ) const
3395{
3396 return constImage()->error.normalized_mean_error;
3397}
3398
3399// Image orientation
3400void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
3401{
3402 modifyImage();
3403 image()->orientation = orientation_;
3404}
3405Magick::OrientationType Magick::Image::orientation ( void ) const
3406{
3407 return constImage()->orientation;
3408}
3409
3410void Magick::Image::penColor ( const Color &penColor_ )
3411{
3412 modifyImage();
3413 options()->fillColor(penColor_);
3414 options()->strokeColor(penColor_);
3415}
3416Magick::Color Magick::Image::penColor ( void ) const
3417{
3418 return constOptions()->fillColor();
3419}
3420
3421void Magick::Image::penTexture ( const Image &penTexture_ )
3422{
3423 modifyImage();
3424 if(penTexture_.isValid())
3425 options()->fillPattern( penTexture_.constImage() );
3426 else
3427 options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
3428}
3429
3430Magick::Image Magick::Image::penTexture ( void ) const
3431{
3432 // FIXME: This is inordinately innefficient
3433 Image texture;
3434
3435 const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
3436
3437 if ( tmpTexture )
3438 {
3439 ExceptionInfo exceptionInfo;
3440 GetExceptionInfo( &exceptionInfo );
3441 MagickCore::Image* image =
3442 CloneImage( tmpTexture,
3443 0, // columns
3444 0, // rows
3445 MagickTrue, // orphan
3446 &exceptionInfo);
3447 texture.replaceImage( image );
3448 throwException( exceptionInfo );
3449 (void) DestroyExceptionInfo( &exceptionInfo );
3450 }
3451 return texture;
3452}
3453
3454// Set the color of a pixel.
cristy35ef8242010-06-03 16:24:13 +00003455void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
cristy3ed852e2009-09-05 21:47:34 +00003456 const Color &color_ )
3457{
3458 // Test arguments to ensure they are within the image.
cristy07fb9182010-06-06 23:37:14 +00003459 if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
cristy3ed852e2009-09-05 21:47:34 +00003460 throwExceptionExplicit( OptionError,
3461 "Access outside of image boundary" );
3462
3463 modifyImage();
3464
3465 // Set image to DirectClass
3466 classType( DirectClass );
3467
3468 // Get pixel view
3469 Pixels pixels(*this);
3470 // Set pixel value
cristy4c08aed2011-07-01 19:47:50 +00003471 Quantum *pixel = pixels.get(x_, y_, 1, 1 );
3472 PixelPacket packet = color_;
3473 MagickCore::SetPixelPacket(constImage(),&packet,pixel);
cristy3ed852e2009-09-05 21:47:34 +00003474 // Tell ImageMagick that pixels have been updated
3475 pixels.sync();
3476
3477 return;
3478}
3479
3480// Get the color of a pixel
cristy35ef8242010-06-03 16:24:13 +00003481Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
3482 const ssize_t y_ ) const
cristy3ed852e2009-09-05 21:47:34 +00003483{
3484 ClassType storage_class;
3485 storage_class = classType();
3486 // DirectClass
cristy4c08aed2011-07-01 19:47:50 +00003487 const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
3488 if ( pixel )
cristy3ed852e2009-09-05 21:47:34 +00003489 {
cristy4c08aed2011-07-01 19:47:50 +00003490 PixelPacket packet;
cristy14083572011-10-01 22:27:02 +00003491 MagickCore::GetPixelPacketPixel(constImage(),pixel,&packet);
cristy4c08aed2011-07-01 19:47:50 +00003492 return Color( packet );
cristy3ed852e2009-09-05 21:47:34 +00003493 }
3494
3495 return Color(); // invalid
3496}
3497
3498// Preferred size and location of an image canvas.
3499void Magick::Image::page ( const Magick::Geometry &pageSize_ )
3500{
3501 modifyImage();
3502 options()->page( pageSize_ );
3503 image()->page = pageSize_;
3504}
3505Magick::Geometry Magick::Image::page ( void ) const
3506{
3507 return Geometry( constImage()->page.width,
3508 constImage()->page.height,
3509 AbsoluteValue(constImage()->page.x),
3510 AbsoluteValue(constImage()->page.y),
3511 constImage()->page.x < 0 ? true : false,
3512 constImage()->page.y < 0 ? true : false);
3513}
3514
3515// Add a named profile to an image or remove a named profile by
3516// passing an empty Blob (use default Blob constructor).
3517// Valid names are:
3518// "*", "8BIM", "ICM", "IPTC", or a generic profile name.
3519void Magick::Image::profile( const std::string name_,
3520 const Magick::Blob &profile_ )
3521{
3522 modifyImage();
cristyd99b0962010-05-29 23:14:26 +00003523 ssize_t result = ProfileImage( image(), name_.c_str(),
cristy3ed852e2009-09-05 21:47:34 +00003524 (unsigned char *)profile_.data(),
3525 profile_.length(), MagickTrue);
3526
3527 if( !result )
3528 throwImageException();
3529}
3530
3531// Retrieve a named profile from the image.
3532// Valid names are:
3533// "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
3534// an existing generic profile name.
3535Magick::Blob Magick::Image::profile( const std::string name_ ) const
3536{
3537 const MagickCore::Image* image = constImage();
3538
3539 const StringInfo * profile = GetImageProfile( image, name_.c_str() );
3540
3541 if ( profile != (StringInfo *) NULL)
3542 return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
3543
3544 Blob blob;
3545 Image temp_image = *this;
3546 temp_image.write( &blob, name_ );
3547 return blob;
3548}
3549
cristyeaedf062010-05-29 22:36:02 +00003550void Magick::Image::quality ( const size_t quality_ )
cristy3ed852e2009-09-05 21:47:34 +00003551{
3552 modifyImage();
3553 image()->quality = quality_;
3554 options()->quality( quality_ );
3555}
cristyeaedf062010-05-29 22:36:02 +00003556size_t Magick::Image::quality ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003557{
3558 return constImage()->quality;
3559}
3560
cristyeaedf062010-05-29 22:36:02 +00003561void Magick::Image::quantizeColors ( const size_t colors_ )
cristy3ed852e2009-09-05 21:47:34 +00003562{
3563 modifyImage();
3564 options()->quantizeColors( colors_ );
3565}
cristyeaedf062010-05-29 22:36:02 +00003566size_t Magick::Image::quantizeColors ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003567{
3568 return constOptions()->quantizeColors( );
3569}
3570
3571void Magick::Image::quantizeColorSpace
3572 ( const Magick::ColorspaceType colorSpace_ )
3573{
3574 modifyImage();
3575 options()->quantizeColorSpace( colorSpace_ );
3576}
3577Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
3578{
3579 return constOptions()->quantizeColorSpace( );
3580}
3581
3582void Magick::Image::quantizeDither ( const bool ditherFlag_ )
3583{
3584 modifyImage();
3585 options()->quantizeDither( ditherFlag_ );
3586}
3587bool Magick::Image::quantizeDither ( void ) const
3588{
3589 return constOptions()->quantizeDither( );
3590}
3591
cristyeaedf062010-05-29 22:36:02 +00003592void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
cristy3ed852e2009-09-05 21:47:34 +00003593{
3594 modifyImage();
3595 options()->quantizeTreeDepth( treeDepth_ );
3596}
cristyeaedf062010-05-29 22:36:02 +00003597size_t Magick::Image::quantizeTreeDepth ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003598{
3599 return constOptions()->quantizeTreeDepth( );
3600}
3601
3602void Magick::Image::renderingIntent
3603 ( const Magick::RenderingIntent renderingIntent_ )
3604{
3605 modifyImage();
3606 image()->rendering_intent = renderingIntent_;
3607}
3608Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
3609{
3610 return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
3611}
3612
3613void Magick::Image::resolutionUnits
3614 ( const Magick::ResolutionType resolutionUnits_ )
3615{
3616 modifyImage();
3617 image()->units = resolutionUnits_;
3618 options()->resolutionUnits( resolutionUnits_ );
3619}
3620Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
3621{
3622 return constOptions()->resolutionUnits( );
3623}
3624
cristyeaedf062010-05-29 22:36:02 +00003625void Magick::Image::scene ( const size_t scene_ )
cristy3ed852e2009-09-05 21:47:34 +00003626{
3627 modifyImage();
3628 image()->scene = scene_;
3629}
cristyeaedf062010-05-29 22:36:02 +00003630size_t Magick::Image::scene ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003631{
3632 return constImage()->scene;
3633}
3634
3635std::string Magick::Image::signature ( const bool force_ ) const
3636{
3637 Lock( &_imgRef->_mutexLock );
3638
3639 // Re-calculate image signature if necessary
cristy018f07f2011-09-04 21:15:19 +00003640 ExceptionInfo exceptionInfo;
3641 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003642 if ( force_ ||
3643 !GetImageProperty(constImage(), "Signature") ||
3644 constImage()->taint )
3645 {
cristy018f07f2011-09-04 21:15:19 +00003646 SignatureImage( const_cast<MagickCore::Image *>(constImage()), &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003647 }
3648
cristy018f07f2011-09-04 21:15:19 +00003649 throwException( exceptionInfo );
3650 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003651 const char *property = GetImageProperty(constImage(), "Signature");
3652
3653 return std::string( property );
3654}
3655
3656void Magick::Image::size ( const Geometry &geometry_ )
3657{
3658 modifyImage();
3659 options()->size( geometry_ );
3660 image()->rows = geometry_.height();
3661 image()->columns = geometry_.width();
3662}
3663Magick::Geometry Magick::Image::size ( void ) const
3664{
3665 return Magick::Geometry( constImage()->columns, constImage()->rows );
3666}
3667
cristy8198a752009-09-28 23:59:24 +00003668// Splice image
3669void Magick::Image::splice( const Geometry &geometry_ )
3670{
3671 RectangleInfo spliceInfo = geometry_;
3672 ExceptionInfo exceptionInfo;
3673 GetExceptionInfo( &exceptionInfo );
3674 MagickCore::Image* newImage =
3675 SpliceImage( image(), &spliceInfo, &exceptionInfo);
3676 replaceImage( newImage );
3677 throwException( exceptionInfo );
3678 (void) DestroyExceptionInfo( &exceptionInfo );
3679}
3680
cristy3ed852e2009-09-05 21:47:34 +00003681// Obtain image statistics. Statistics are normalized to the range of
3682// 0.0 to 1.0 and are output to the specified ImageStatistics
3683// structure.
cristyd42d9952011-07-08 14:21:50 +00003684void Magick::Image::statistics ( ImageStatistics *statistics )
cristy3ed852e2009-09-05 21:47:34 +00003685{
3686 double
3687 maximum,
3688 minimum;
3689
3690 ExceptionInfo exceptionInfo;
3691 GetExceptionInfo( &exceptionInfo );
cristyd42d9952011-07-08 14:21:50 +00003692
cristybd5a96c2011-08-21 00:04:26 +00003693 ChannelType channel_mask = SetPixelChannelMask( image(), RedChannel);
cristyd42d9952011-07-08 14:21:50 +00003694 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003695 statistics->red.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003696 statistics->red.maximum=maximum;
3697 (void) GetImageMean( image(),&statistics->red.mean,
3698 &statistics->red.standard_deviation,&exceptionInfo);
3699 (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
3700 &statistics->red.skewness,&exceptionInfo);
cristybd5a96c2011-08-21 00:04:26 +00003701 (void) SetPixelChannelMap( image(), channel_mask );
cristyd42d9952011-07-08 14:21:50 +00003702
cristybd5a96c2011-08-21 00:04:26 +00003703 channel_mask = SetPixelChannelMask( image(), GreenChannel);
cristyd42d9952011-07-08 14:21:50 +00003704 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003705 statistics->green.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003706 statistics->green.maximum=maximum;
3707 (void) GetImageMean( image(),&statistics->green.mean,
3708 &statistics->green.standard_deviation,&exceptionInfo);
3709 (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
3710 &statistics->green.skewness,&exceptionInfo);
cristybd5a96c2011-08-21 00:04:26 +00003711 (void) SetPixelChannelMap( image(), channel_mask );
cristyd42d9952011-07-08 14:21:50 +00003712
cristybd5a96c2011-08-21 00:04:26 +00003713 channel_mask = SetPixelChannelMask( image(), GreenChannel);
cristyd42d9952011-07-08 14:21:50 +00003714 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003715 statistics->blue.minimum=minimum;
cristyd42d9952011-07-08 14:21:50 +00003716 statistics->blue.maximum=maximum;
3717 (void) GetImageMean( image(),&statistics->blue.mean,
3718 &statistics->blue.standard_deviation,&exceptionInfo);
3719 (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
3720 &statistics->blue.skewness,&exceptionInfo);
cristybd5a96c2011-08-21 00:04:26 +00003721 (void) SetPixelChannelMap( image(), channel_mask );
cristyd42d9952011-07-08 14:21:50 +00003722
cristybd5a96c2011-08-21 00:04:26 +00003723 channel_mask = SetPixelChannelMask( image(), AlphaChannel);
cristyd42d9952011-07-08 14:21:50 +00003724 (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
cristy4c08aed2011-07-01 19:47:50 +00003725 statistics->alpha.minimum=minimum;
3726 statistics->alpha.maximum=maximum;
cristyd42d9952011-07-08 14:21:50 +00003727 (void) GetImageMean( image(),&statistics->alpha.mean,
3728 &statistics->alpha.standard_deviation,&exceptionInfo);
3729 (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
3730 &statistics->alpha.skewness,&exceptionInfo);
cristybd5a96c2011-08-21 00:04:26 +00003731 (void) SetPixelChannelMap( image(), channel_mask );
cristyd42d9952011-07-08 14:21:50 +00003732
cristy3ed852e2009-09-05 21:47:34 +00003733 throwException( exceptionInfo );
3734 (void) DestroyExceptionInfo( &exceptionInfo );
3735}
3736
cristy9f89a3f2011-02-12 17:02:35 +00003737// Strip strips an image of all profiles and comments.
3738void Magick::Image::strip ( void )
3739{
3740 modifyImage();
3741 StripImage( image() );
3742 throwImageException();
3743}
3744
cristy3ed852e2009-09-05 21:47:34 +00003745// enabled/disable stroke anti-aliasing
3746void Magick::Image::strokeAntiAlias ( const bool flag_ )
3747{
3748 modifyImage();
3749 options()->strokeAntiAlias(flag_);
3750}
3751bool Magick::Image::strokeAntiAlias ( void ) const
3752{
3753 return constOptions()->strokeAntiAlias();
3754}
3755
3756// Color to use when drawing object outlines
3757void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
3758{
3759 modifyImage();
3760 options()->strokeColor(strokeColor_);
3761}
3762Magick::Color Magick::Image::strokeColor ( void ) const
3763{
3764 return constOptions()->strokeColor();
3765}
3766
3767// dash pattern for drawing vector objects (default one)
3768void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
3769{
3770 modifyImage();
3771 options()->strokeDashArray( strokeDashArray_ );
3772}
3773
3774const double* Magick::Image::strokeDashArray ( void ) const
3775{
3776 return constOptions()->strokeDashArray( );
3777}
3778
3779// dash offset for drawing vector objects (default one)
3780void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
3781{
3782 modifyImage();
3783 options()->strokeDashOffset( strokeDashOffset_ );
3784}
3785
3786double Magick::Image::strokeDashOffset ( void ) const
3787{
3788 return constOptions()->strokeDashOffset( );
3789}
3790
3791// Specify the shape to be used at the end of open subpaths when they
3792// are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
3793// and SquareCap.
3794void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
3795{
3796 modifyImage();
3797 options()->strokeLineCap( lineCap_ );
3798}
3799Magick::LineCap Magick::Image::strokeLineCap ( void ) const
3800{
3801 return constOptions()->strokeLineCap( );
3802}
3803
3804// Specify the shape to be used at the corners of paths (or other
3805// vector shapes) when they are stroked. Values of LineJoin are
3806// UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
3807void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
3808{
3809 modifyImage();
3810 options()->strokeLineJoin( lineJoin_ );
3811}
3812Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
3813{
3814 return constOptions()->strokeLineJoin( );
3815}
3816
3817// Specify miter limit. When two line segments meet at a sharp angle
3818// and miter joins have been specified for 'lineJoin', it is possible
3819// for the miter to extend far beyond the thickness of the line
3820// stroking the path. The miterLimit' imposes a limit on the ratio of
3821// the miter length to the 'lineWidth'. The default value of this
3822// parameter is 4.
cristyeaedf062010-05-29 22:36:02 +00003823void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
cristy3ed852e2009-09-05 21:47:34 +00003824{
3825 modifyImage();
3826 options()->strokeMiterLimit( strokeMiterLimit_ );
3827}
cristyeaedf062010-05-29 22:36:02 +00003828size_t Magick::Image::strokeMiterLimit ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003829{
3830 return constOptions()->strokeMiterLimit( );
3831}
3832
3833// Pattern to use while stroking drawn objects.
3834void Magick::Image::strokePattern ( const Image &strokePattern_ )
3835{
3836 modifyImage();
3837 if(strokePattern_.isValid())
3838 options()->strokePattern( strokePattern_.constImage() );
3839 else
3840 options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
3841}
3842Magick::Image Magick::Image::strokePattern ( void ) const
3843{
3844 // FIXME: This is inordinately innefficient
3845 Image texture;
3846
3847 const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
3848
3849 if ( tmpTexture )
3850 {
3851 ExceptionInfo exceptionInfo;
3852 GetExceptionInfo( &exceptionInfo );
3853 MagickCore::Image* image =
3854 CloneImage( tmpTexture,
3855 0, // columns
3856 0, // rows
3857 MagickTrue, // orphan
3858 &exceptionInfo);
3859 throwException( exceptionInfo );
3860 (void) DestroyExceptionInfo( &exceptionInfo );
3861 texture.replaceImage( image );
3862 }
3863 return texture;
3864}
3865
3866// Stroke width for drawing lines, circles, ellipses, etc.
3867void Magick::Image::strokeWidth ( const double strokeWidth_ )
3868{
3869 modifyImage();
3870 options()->strokeWidth( strokeWidth_ );
3871}
3872double Magick::Image::strokeWidth ( void ) const
3873{
3874 return constOptions()->strokeWidth( );
3875}
3876
cristyeaedf062010-05-29 22:36:02 +00003877void Magick::Image::subImage ( const size_t subImage_ )
cristy3ed852e2009-09-05 21:47:34 +00003878{
3879 modifyImage();
3880 options()->subImage( subImage_ );
3881}
cristyeaedf062010-05-29 22:36:02 +00003882size_t Magick::Image::subImage ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003883{
3884 return constOptions()->subImage( );
3885}
3886
cristyeaedf062010-05-29 22:36:02 +00003887void Magick::Image::subRange ( const size_t subRange_ )
cristy3ed852e2009-09-05 21:47:34 +00003888{
3889 modifyImage();
3890 options()->subRange( subRange_ );
3891}
cristyeaedf062010-05-29 22:36:02 +00003892size_t Magick::Image::subRange ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00003893{
3894 return constOptions()->subRange( );
3895}
3896
3897// Annotation text encoding (e.g. "UTF-16")
3898void Magick::Image::textEncoding ( const std::string &encoding_ )
3899{
3900 modifyImage();
3901 options()->textEncoding( encoding_ );
3902}
3903std::string Magick::Image::textEncoding ( void ) const
3904{
3905 return constOptions()->textEncoding( );
3906}
3907
cristybb503372010-05-27 20:51:26 +00003908size_t Magick::Image::totalColors ( void )
cristy3ed852e2009-09-05 21:47:34 +00003909{
3910 ExceptionInfo exceptionInfo;
3911 GetExceptionInfo( &exceptionInfo );
cristybb503372010-05-27 20:51:26 +00003912 size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
cristy3ed852e2009-09-05 21:47:34 +00003913 throwException( exceptionInfo );
3914 (void) DestroyExceptionInfo( &exceptionInfo );
3915 return colors;
3916}
3917
3918// Origin of coordinate system to use when annotating with text or drawing
3919void Magick::Image::transformOrigin ( const double x_, const double y_ )
3920{
3921 modifyImage();
3922 options()->transformOrigin( x_, y_ );
3923}
3924
3925// Rotation to use when annotating with text or drawing
3926void Magick::Image::transformRotation ( const double angle_ )
3927{
3928 modifyImage();
3929 options()->transformRotation( angle_ );
3930}
3931
3932// Reset transformation parameters to default
3933void Magick::Image::transformReset ( void )
3934{
3935 modifyImage();
3936 options()->transformReset();
3937}
3938
3939// Scale to use when annotating with text or drawing
3940void Magick::Image::transformScale ( const double sx_, const double sy_ )
3941{
3942 modifyImage();
3943 options()->transformScale( sx_, sy_ );
3944}
3945
3946// Skew to use in X axis when annotating with text or drawing
3947void Magick::Image::transformSkewX ( const double skewx_ )
3948{
3949 modifyImage();
3950 options()->transformSkewX( skewx_ );
3951}
3952
3953// Skew to use in Y axis when annotating with text or drawing
3954void Magick::Image::transformSkewY ( const double skewy_ )
3955{
3956 modifyImage();
3957 options()->transformSkewY( skewy_ );
3958}
3959
3960// Image representation type
3961Magick::ImageType Magick::Image::type ( void ) const
3962{
3963
3964 ExceptionInfo exceptionInfo;
3965 GetExceptionInfo( &exceptionInfo );
3966 ImageType image_type = constOptions()->type();
3967 if ( image_type == UndefinedType )
3968 image_type= GetImageType( constImage(), &exceptionInfo);
3969 throwException( exceptionInfo );
3970 (void) DestroyExceptionInfo( &exceptionInfo );
3971 return image_type;
3972}
3973void Magick::Image::type ( const Magick::ImageType type_)
3974{
cristy018f07f2011-09-04 21:15:19 +00003975 ExceptionInfo exceptionInfo;
3976 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003977 modifyImage();
3978 options()->type( type_ );
cristy018f07f2011-09-04 21:15:19 +00003979 SetImageType( image(), type_, &exceptionInfo );
3980 throwException( exceptionInfo );
3981 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +00003982}
3983
3984void Magick::Image::verbose ( const bool verboseFlag_ )
3985{
3986 modifyImage();
3987 options()->verbose( verboseFlag_ );
3988}
3989bool Magick::Image::verbose ( void ) const
3990{
3991 return constOptions()->verbose( );
3992}
3993
3994void Magick::Image::view ( const std::string &view_ )
3995{
3996 modifyImage();
3997 options()->view( view_ );
3998}
3999std::string Magick::Image::view ( void ) const
4000{
4001 return constOptions()->view( );
4002}
4003
4004// Virtual pixel method
4005void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
4006{
4007 modifyImage();
4008 SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
4009 options()->virtualPixelMethod( virtual_pixel_method_ );
4010}
4011Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
4012{
4013 return GetImageVirtualPixelMethod( constImage() );
4014}
4015
4016void Magick::Image::x11Display ( const std::string &display_ )
4017{
4018 modifyImage();
4019 options()->x11Display( display_ );
4020}
4021std::string Magick::Image::x11Display ( void ) const
4022{
4023 return constOptions()->x11Display( );
4024}
4025
4026double Magick::Image::xResolution ( void ) const
4027{
4028 return constImage()->x_resolution;
4029}
4030double Magick::Image::yResolution ( void ) const
4031{
4032 return constImage()->y_resolution;
4033}
4034
4035// Copy Constructor
4036Magick::Image::Image( const Image & image_ )
4037 : _imgRef(image_._imgRef)
4038{
4039 Lock( &_imgRef->_mutexLock );
4040
4041 // Increase reference count
4042 ++_imgRef->_refCount;
4043}
4044
4045// Assignment operator
4046Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
4047{
4048 if( this != &image_ )
4049 {
4050 {
4051 Lock( &image_._imgRef->_mutexLock );
4052 ++image_._imgRef->_refCount;
4053 }
4054
4055 bool doDelete = false;
4056 {
4057 Lock( &_imgRef->_mutexLock );
4058 if ( --_imgRef->_refCount == 0 )
4059 doDelete = true;
4060 }
4061
4062 if ( doDelete )
4063 {
4064 // Delete old image reference with associated image and options.
4065 delete _imgRef;
4066 _imgRef = 0;
4067 }
4068 // Use new image reference
4069 _imgRef = image_._imgRef;
4070 }
4071
4072 return *this;
4073}
4074
4075//////////////////////////////////////////////////////////////////////
4076//
4077// Low-level Pixel Access Routines
4078//
4079// Also see the Pixels class, which provides support for multiple
4080// cache views. The low-level pixel access routines in the Image
4081// class are provided in order to support backward compatability.
4082//
4083//////////////////////////////////////////////////////////////////////
4084
4085// Transfers read-only pixels from the image to the pixel cache as
4086// defined by the specified region
cristy4c08aed2011-07-01 19:47:50 +00004087const Magick::Quantum* Magick::Image::getConstPixels
cristyd99b0962010-05-29 23:14:26 +00004088 ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00004089 const size_t columns_,
4090 const size_t rows_ ) const
cristy3ed852e2009-09-05 21:47:34 +00004091{
4092 ExceptionInfo exceptionInfo;
4093 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00004094 const Quantum* p = (*GetVirtualPixels)( constImage(),
cristy3ed852e2009-09-05 21:47:34 +00004095 x_, y_,
4096 columns_, rows_,
4097 &exceptionInfo );
4098 throwException( exceptionInfo );
4099 (void) DestroyExceptionInfo( &exceptionInfo );
4100 return p;
4101}
4102
cristy4c08aed2011-07-01 19:47:50 +00004103// Obtain read-only pixel associated pixels channels
4104const void* Magick::Image::getConstMetacontent ( void ) const
cristy3ed852e2009-09-05 21:47:34 +00004105{
cristy4c08aed2011-07-01 19:47:50 +00004106 const void* result = GetVirtualMetacontent( constImage() );
cristy3ed852e2009-09-05 21:47:34 +00004107
4108 if( !result )
4109 throwImageException();
4110
4111 return result;
4112}
4113
cristy4c08aed2011-07-01 19:47:50 +00004114// Obtain image pixel associated pixels channels
4115void* Magick::Image::getMetacontent ( void )
cristy3ed852e2009-09-05 21:47:34 +00004116{
cristy4c08aed2011-07-01 19:47:50 +00004117 void* result = GetAuthenticMetacontent( image() );
cristy3ed852e2009-09-05 21:47:34 +00004118
4119 if( !result )
4120 throwImageException();
4121
4122 return ( result );
4123}
4124
4125// Transfers pixels from the image to the pixel cache as defined
4126// by the specified region. Modified pixels may be subsequently
4127// transferred back to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00004128Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00004129 const size_t columns_,
4130 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00004131{
4132 modifyImage();
4133 ExceptionInfo exceptionInfo;
4134 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00004135 Quantum* result = (*GetAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00004136 x_, y_,
4137 columns_, rows_, &exceptionInfo );
4138 throwException( exceptionInfo );
4139 (void) DestroyExceptionInfo( &exceptionInfo );
4140
4141 return result;
4142}
4143
4144// Allocates a pixel cache region to store image pixels as defined
4145// by the region rectangle. This area is subsequently transferred
4146// from the pixel cache to the image via syncPixels.
cristy4c08aed2011-07-01 19:47:50 +00004147Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
cristyeaedf062010-05-29 22:36:02 +00004148 const size_t columns_,
4149 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +00004150{
4151 modifyImage();
4152 ExceptionInfo exceptionInfo;
4153 GetExceptionInfo( &exceptionInfo );
cristy4c08aed2011-07-01 19:47:50 +00004154 Quantum* result = (*QueueAuthenticPixels)( image(),
cristy3ed852e2009-09-05 21:47:34 +00004155 x_, y_,
4156 columns_, rows_, &exceptionInfo );
4157 throwException( exceptionInfo );
4158 (void) DestroyExceptionInfo( &exceptionInfo );
4159
4160 return result;
4161}
4162
4163// Transfers the image cache pixels to the image.
4164void Magick::Image::syncPixels ( void )
4165{
4166 ExceptionInfo exceptionInfo;
4167 GetExceptionInfo( &exceptionInfo );
4168 (*SyncAuthenticPixels)( image(), &exceptionInfo );
4169 throwException( exceptionInfo );
4170 (void) DestroyExceptionInfo( &exceptionInfo );
4171}
4172
4173// Transfers one or more pixel components from a buffer or file
4174// into the image pixel cache of an image.
4175// Used to support image decoders.
4176void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
4177 const unsigned char *source_ )
4178{
4179 QuantumInfo
4180 *quantum_info;
4181
4182 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4183 ExceptionInfo exceptionInfo;
4184 GetExceptionInfo( &exceptionInfo );
4185 ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4186 quantum_,source_, &exceptionInfo);
4187 throwException( exceptionInfo );
4188 (void) DestroyExceptionInfo( &exceptionInfo );
4189 quantum_info=DestroyQuantumInfo(quantum_info);
4190}
4191
4192// Transfers one or more pixel components from the image pixel
4193// cache to a buffer or file.
4194// Used to support image encoders.
4195void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
4196 unsigned char *destination_ )
4197{
4198 QuantumInfo
4199 *quantum_info;
4200
4201 quantum_info=AcquireQuantumInfo(imageInfo(),image());
4202 ExceptionInfo exceptionInfo;
4203 GetExceptionInfo( &exceptionInfo );
4204 ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
4205 quantum_,destination_, &exceptionInfo);
4206 quantum_info=DestroyQuantumInfo(quantum_info);
4207 throwException( exceptionInfo );
4208 (void) DestroyExceptionInfo( &exceptionInfo );
4209}
4210
4211/////////////////////////////////////////////////////////////////////
4212//
4213// No end-user methods beyond this point
4214//
4215/////////////////////////////////////////////////////////////////////
4216
4217
4218//
4219// Construct using existing image and default options
4220//
4221Magick::Image::Image ( MagickCore::Image* image_ )
4222 : _imgRef(new ImageRef( image_))
4223{
4224}
4225
4226// Get Magick::Options*
4227Magick::Options* Magick::Image::options( void )
4228{
4229 return _imgRef->options();
4230}
4231const Magick::Options* Magick::Image::constOptions( void ) const
4232{
4233 return _imgRef->options();
4234}
4235
4236// Get MagickCore::Image*
4237MagickCore::Image*& Magick::Image::image( void )
4238{
4239 return _imgRef->image();
4240}
4241const MagickCore::Image* Magick::Image::constImage( void ) const
4242{
4243 return _imgRef->image();
4244}
4245
4246// Get ImageInfo *
4247MagickCore::ImageInfo* Magick::Image::imageInfo( void )
4248{
4249 return _imgRef->options()->imageInfo();
4250}
4251const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
4252{
4253 return _imgRef->options()->imageInfo();
4254}
4255
4256// Get QuantizeInfo *
4257MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
4258{
4259 return _imgRef->options()->quantizeInfo();
4260}
4261const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
4262{
4263 return _imgRef->options()->quantizeInfo();
4264}
4265
4266//
4267// Replace current image
4268//
4269MagickCore::Image * Magick::Image::replaceImage
4270 ( MagickCore::Image* replacement_ )
4271{
4272 MagickCore::Image* image;
4273
4274 if( replacement_ )
4275 image = replacement_;
4276 else
cristy9950d572011-10-01 18:22:35 +00004277 {
4278 ExceptionInfo exceptionInfo;
4279 GetExceptionInfo( &exceptionInfo );
4280 image = AcquireImage(constImageInfo(), &exceptionInfo);
4281 throwException( exceptionInfo );
4282 (void) DestroyExceptionInfo( &exceptionInfo );
4283 }
cristy3ed852e2009-09-05 21:47:34 +00004284
4285 {
4286 Lock( &_imgRef->_mutexLock );
4287
4288 if ( _imgRef->_refCount == 1 )
4289 {
4290 // We own the image, just replace it, and de-register
4291 _imgRef->id( -1 );
4292 _imgRef->image(image);
4293 }
4294 else
4295 {
4296 // We don't own the image, dereference and replace with copy
4297 --_imgRef->_refCount;
4298 _imgRef = new ImageRef( image, constOptions() );
4299 }
4300 }
4301
4302 return _imgRef->_image;
4303}
4304
4305//
4306// Prepare to modify image or image options
4307// Replace current image and options with copy if reference count > 1
4308//
4309void Magick::Image::modifyImage( void )
4310{
4311 {
4312 Lock( &_imgRef->_mutexLock );
4313 if ( _imgRef->_refCount == 1 )
4314 {
4315 // De-register image and return
4316 _imgRef->id( -1 );
4317 return;
4318 }
4319 }
4320
4321 ExceptionInfo exceptionInfo;
4322 GetExceptionInfo( &exceptionInfo );
4323 replaceImage( CloneImage( image(),
4324 0, // columns
4325 0, // rows
4326 MagickTrue, // orphan
4327 &exceptionInfo) );
4328 throwException( exceptionInfo );
4329 (void) DestroyExceptionInfo( &exceptionInfo );
4330 return;
4331}
4332
4333//
4334// Test for an ImageMagick reported error and throw exception if one
4335// has been reported. Secretly resets image->exception back to default
4336// state even though this method is const.
4337//
4338void Magick::Image::throwImageException( void ) const
4339{
4340 // Throw C++ exception while resetting Image exception to default state
4341 throwException( const_cast<MagickCore::Image*>(constImage())->exception );
4342}
4343
4344// Register image with image registry or obtain registration id
cristybb503372010-05-27 20:51:26 +00004345ssize_t Magick::Image::registerId( void )
cristy3ed852e2009-09-05 21:47:34 +00004346{
4347 Lock( &_imgRef->_mutexLock );
4348 if( _imgRef->id() < 0 )
4349 {
4350 char id[MaxTextExtent];
4351 ExceptionInfo exceptionInfo;
4352 GetExceptionInfo( &exceptionInfo );
4353 _imgRef->id(_imgRef->id()+1);
cristye8c25f92010-06-03 00:53:06 +00004354 sprintf(id,"%.20g\n",(double) _imgRef->id());
cristy3ed852e2009-09-05 21:47:34 +00004355 SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
4356 throwException( exceptionInfo );
4357 (void) DestroyExceptionInfo( &exceptionInfo );
4358 }
4359 return _imgRef->id();
4360}
4361
4362// Unregister image from image registry
4363void Magick::Image::unregisterId( void )
4364{
4365 modifyImage();
4366 _imgRef->id( -1 );
4367}
4368
4369//
4370// Create a local wrapper around MagickCoreTerminus
4371//
4372namespace Magick
4373{
4374 extern "C" {
4375 void MagickPlusPlusDestroyMagick(void);
4376 }
4377}
4378
4379void Magick::MagickPlusPlusDestroyMagick(void)
4380{
4381 if (magick_initialized)
4382 {
4383 magick_initialized=false;
4384 MagickCore::MagickCoreTerminus();
4385 }
4386}
4387
4388// C library initialization routine
cristyaf1dd252011-09-07 19:04:02 +00004389void MagickPPExport Magick::InitializeMagick(const char *path_)
cristy3ed852e2009-09-05 21:47:34 +00004390{
4391 MagickCore::MagickCoreGenesis(path_,MagickFalse);
4392 if (!magick_initialized)
4393 magick_initialized=true;
4394}
4395
4396//
4397// Cleanup class to ensure that ImageMagick singletons are destroyed
4398// so as to avoid any resemblence to a memory leak (which seems to
4399// confuse users)
4400//
4401namespace Magick
4402{
4403
4404 class MagickCleanUp
4405 {
4406 public:
4407 MagickCleanUp( void );
4408 ~MagickCleanUp( void );
4409 };
4410
4411 // The destructor for this object is invoked when the destructors for
4412 // static objects in this translation unit are invoked.
4413 static MagickCleanUp magickCleanUpGuard;
4414}
4415
4416Magick::MagickCleanUp::MagickCleanUp ( void )
4417{
4418 // Don't even think about invoking InitializeMagick here!
4419}
4420
4421Magick::MagickCleanUp::~MagickCleanUp ( void )
4422{
4423 MagickPlusPlusDestroyMagick();
4424}