blob: a5445cc830ba121ad307da3c8f3d7be789b0c234 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002
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
18Magick::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.
29Magick::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
41Magick::ImageRef::ImageRef ( void )
42 : _image(0),
43 _options(new Options),
44 _id(-1),
45 _refCount(1),
46 _mutexLock()
47{
48 // Allocate default image
cristyc82a27b2011-10-21 01:07:16 +000049 ExceptionInfo exceptionInfo;
50 GetExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +000051
cristyc82a27b2011-10-21 01:07:16 +000052 _image = AcquireImage( _options->imageInfo(), &exceptionInfo );
53 throwException( exceptionInfo );
54 (void) DestroyExceptionInfo( &exceptionInfo );
cristy3ed852e2009-09-05 21:47:34 +000055}
56
57// Destructor
58Magick::ImageRef::~ImageRef( void )
59{
60 // Unregister image (if still registered)
61 if( _id > -1 )
62 {
63 char id[MaxTextExtent];
cristye8c25f92010-06-03 00:53:06 +000064 sprintf(id,"%.20g",(double) _id);
cristy3ed852e2009-09-05 21:47:34 +000065 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
82void Magick::ImageRef::image ( MagickCore::Image * image_ )
83{
84 if(_image)
85 DestroyImageList( _image );
86 _image = image_;
87}
88
89// Assign options to reference
90void Magick::ImageRef::options ( Magick::Options * options_ )
91{
92 delete _options;
93 _options = options_;
94}
95
96// Assign registration id to reference
cristybb503372010-05-27 20:51:26 +000097void Magick::ImageRef::id ( const ssize_t id_ )
cristy3ed852e2009-09-05 21:47:34 +000098{
99 if( _id > -1 )
100 {
101 char id[MaxTextExtent];
cristye8c25f92010-06-03 00:53:06 +0000102 sprintf(id,"%.20g",(double) _id);
cristy3ed852e2009-09-05 21:47:34 +0000103 DeleteImageRegistry( id );
104 }
105 _id = id_;
106}