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 |
| 4 | // |
| 5 | // Implementation of ImageRef |
| 6 | // |
| 7 | // This is an internal implementation class. |
| 8 | // |
| 9 | |
| 10 | #define MAGICKCORE_IMPLEMENTATION 1 |
| 11 | #define MAGICK_PLUSPLUS_IMPLEMENTATION 1 |
| 12 | |
| 13 | #include "Magick++/ImageRef.h" |
| 14 | #include "Magick++/Exception.h" |
| 15 | #include "Magick++/Options.h" |
| 16 | |
| 17 | // Construct with an image and default options |
| 18 | Magick::ImageRef::ImageRef ( MagickCore::Image * image_ ) |
| 19 | : _image(image_), |
| 20 | _options(new Options), |
| 21 | _id(-1), |
| 22 | _refCount(1), |
| 23 | _mutexLock() |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | // Construct with an image and options |
| 28 | // Inserts Image* in image, but copies Options into image. |
| 29 | Magick::ImageRef::ImageRef ( MagickCore::Image * image_, |
| 30 | const Options * options_ ) |
| 31 | : _image(image_), |
| 32 | _options(0), |
| 33 | _id(-1), |
| 34 | _refCount(1), |
| 35 | _mutexLock() |
| 36 | { |
| 37 | _options = new Options( *options_ ); |
| 38 | } |
| 39 | |
| 40 | // Default constructor |
| 41 | Magick::ImageRef::ImageRef ( void ) |
| 42 | : _image(0), |
| 43 | _options(new Options), |
| 44 | _id(-1), |
| 45 | _refCount(1), |
| 46 | _mutexLock() |
| 47 | { |
| 48 | // Allocate default image |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 49 | ExceptionInfo exceptionInfo; |
| 50 | GetExceptionInfo( &exceptionInfo ); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 51 | |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 52 | _image = AcquireImage( _options->imageInfo(), &exceptionInfo ); |
| 53 | throwException( exceptionInfo ); |
| 54 | (void) DestroyExceptionInfo( &exceptionInfo ); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // Destructor |
| 58 | Magick::ImageRef::~ImageRef( void ) |
| 59 | { |
| 60 | // Unregister image (if still registered) |
| 61 | if( _id > -1 ) |
| 62 | { |
| 63 | char id[MaxTextExtent]; |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 64 | sprintf(id,"%.20g",(double) _id); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | DeleteImageRegistry( id ); |
| 66 | _id=-1; |
| 67 | } |
| 68 | |
| 69 | // Deallocate image |
| 70 | if ( _image ) |
| 71 | { |
| 72 | DestroyImageList( _image ); |
| 73 | _image = 0; |
| 74 | } |
| 75 | |
| 76 | // Deallocate image options |
| 77 | delete _options; |
| 78 | _options = 0; |
| 79 | } |
| 80 | |
| 81 | // Assign image to reference |
| 82 | void Magick::ImageRef::image ( MagickCore::Image * image_ ) |
| 83 | { |
| 84 | if(_image) |
| 85 | DestroyImageList( _image ); |
| 86 | _image = image_; |
| 87 | } |
| 88 | |
| 89 | // Assign options to reference |
| 90 | void Magick::ImageRef::options ( Magick::Options * options_ ) |
| 91 | { |
| 92 | delete _options; |
| 93 | _options = options_; |
| 94 | } |
| 95 | |
| 96 | // Assign registration id to reference |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 97 | void Magick::ImageRef::id ( const ssize_t id_ ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 98 | { |
| 99 | if( _id > -1 ) |
| 100 | { |
| 101 | char id[MaxTextExtent]; |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 102 | sprintf(id,"%.20g",(double) _id); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | DeleteImageRegistry( id ); |
| 104 | } |
| 105 | _id = id_; |
| 106 | } |