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