]> granicus.if.org Git - imagemagick/blob - Magick++/lib/ImageRef.cpp
(no commit message)
[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   _image = AcquireImage( _options->imageInfo() );
50
51   // Test for error and throw exception (like throwImageException())
52   throwException(_image->exception);
53 }
54
55 // Destructor
56 Magick::ImageRef::~ImageRef( void )
57 {
58   // Unregister image (if still registered)
59   if( _id > -1 )
60     {
61       char id[MaxTextExtent];
62       sprintf(id,"%.20g",(double) _id);
63       DeleteImageRegistry( id );
64       _id=-1;
65     }
66
67   // Deallocate image
68   if ( _image )
69     {
70       DestroyImageList( _image );
71       _image = 0;
72     }
73
74   // Deallocate image options
75   delete _options;
76   _options = 0;
77 }
78
79 // Assign image to reference
80 void Magick::ImageRef::image ( MagickCore::Image * image_ )
81 {
82   if(_image)
83     DestroyImageList( _image );
84   _image = image_;
85 }
86
87 // Assign options to reference
88 void  Magick::ImageRef::options ( Magick::Options * options_ )
89 {
90   delete _options;
91   _options = options_;
92 }
93
94 // Assign registration id to reference
95 void Magick::ImageRef::id ( const ssize_t id_ )
96 {
97   if( _id > -1 )
98     {
99       char id[MaxTextExtent];
100       sprintf(id,"%.20g",(double) _id);
101       DeleteImageRegistry( id );
102     }
103   _id = id_;
104 }