/src/graphicsmagick/Magick++/lib/ImageRef.cpp
Line | Count | Source |
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 MAGICK_IMPLEMENTATION |
11 | | #define MAGICK_PLUSPLUS_IMPLEMENTATION |
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 ( MagickLib::Image * image_ ) |
19 | 0 | : _image(image_), |
20 | 0 | _options(new Options), |
21 | 0 | _id(-1), |
22 | 0 | _refCount(1), |
23 | 0 | _mutexLock() |
24 | 0 | { |
25 | 0 | } |
26 | | |
27 | | // Construct with an image and options |
28 | | // Inserts Image* in image, but copies Options into image. |
29 | | Magick::ImageRef::ImageRef ( MagickLib::Image * image_, |
30 | | const Options * options_ ) |
31 | 0 | : _image(image_), |
32 | 0 | _options(0), |
33 | 0 | _id(-1), |
34 | 0 | _refCount(1), |
35 | 0 | _mutexLock() |
36 | 0 | { |
37 | 0 | _options = new Options( *options_ ); |
38 | 0 | } |
39 | | |
40 | | // Default constructor |
41 | | Magick::ImageRef::ImageRef ( void ) |
42 | 578k | : _image(0), |
43 | 578k | _options(new Options), |
44 | 578k | _id(-1), |
45 | 578k | _refCount(1), |
46 | 578k | _mutexLock() |
47 | 578k | { |
48 | | // Allocate default image |
49 | 578k | _image = AllocateImage( _options->imageInfo() ); |
50 | | |
51 | | // Test for error and throw exception (like throwImageException()) |
52 | 578k | throwException(_image->exception); |
53 | 578k | } |
54 | | |
55 | | // Destructor |
56 | | Magick::ImageRef::~ImageRef( void ) |
57 | 578k | { |
58 | | // Unregister image (if still registered) |
59 | 578k | if( _id > -1 ) |
60 | 0 | { |
61 | 0 | DeleteMagickRegistry( _id ); |
62 | 0 | _id=-1; |
63 | 0 | } |
64 | | |
65 | | // Deallocate image |
66 | 578k | if ( _image ) |
67 | 578k | { |
68 | 578k | DestroyImageList( _image ); |
69 | 578k | _image = 0; |
70 | 578k | } |
71 | | |
72 | | // Deallocate image options |
73 | 578k | delete _options; |
74 | 578k | _options = 0; |
75 | 578k | } |
76 | | |
77 | | // Assign image to reference |
78 | | void Magick::ImageRef::image ( MagickLib::Image * image_ ) |
79 | 579k | { |
80 | 579k | if(_image) |
81 | 579k | DestroyImageList( _image ); |
82 | 579k | _image = image_; |
83 | 579k | } |
84 | | |
85 | | // Assign options to reference |
86 | | void Magick::ImageRef::options ( Magick::Options * options_ ) |
87 | 0 | { |
88 | 0 | delete _options; |
89 | 0 | _options = options_; |
90 | 0 | } |
91 | | |
92 | | // Assign registration id to reference |
93 | | void Magick::ImageRef::id ( const long id_ ) |
94 | 2.39M | { |
95 | 2.39M | if( _id > -1 ) |
96 | 0 | DeleteMagickRegistry( _id ); |
97 | 2.39M | _id = id_; |
98 | 2.39M | } |