]> granicus.if.org Git - imagemagick/blob - Magick++/lib/ImageRef.cpp
Updated CompositeOperator values.
[imagemagick] / Magick++ / lib / ImageRef.cpp
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
49   ExceptionInfo exceptionInfo;
50   GetExceptionInfo( &exceptionInfo );
51
52   _image = AcquireImage( _options->imageInfo(), &exceptionInfo );
53   throwException( exceptionInfo );
54   (void) DestroyExceptionInfo( &exceptionInfo );
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];
64       sprintf(id,"%.20g",(double) _id);
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
97 void Magick::ImageRef::id ( const ssize_t id_ )
98 {
99   if( _id > -1 )
100     {
101       char id[MaxTextExtent];
102       sprintf(id,"%.20g",(double) _id);
103       DeleteImageRegistry( id );
104     }
105   _id = id_;
106 }