blob: c736a897432c4fff7c07ff99cf50b5588df56803 [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
49 _image = AcquireImage( _options->imageInfo() );
50
51 // Test for error and throw exception (like throwImageException())
52 throwException(_image->exception);
53}
54
55// Destructor
56Magick::ImageRef::~ImageRef( void )
57{
58 // Unregister image (if still registered)
59 if( _id > -1 )
60 {
61 char id[MaxTextExtent];
cristye8c25f92010-06-03 00:53:06 +000062 sprintf(id,"%.20g",(double) _id);
cristy3ed852e2009-09-05 21:47:34 +000063 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
80void Magick::ImageRef::image ( MagickCore::Image * image_ )
81{
82 if(_image)
83 DestroyImageList( _image );
84 _image = image_;
85}
86
87// Assign options to reference
88void Magick::ImageRef::options ( Magick::Options * options_ )
89{
90 delete _options;
91 _options = options_;
92}
93
94// Assign registration id to reference
cristybb503372010-05-27 20:51:26 +000095void Magick::ImageRef::id ( const ssize_t id_ )
cristy3ed852e2009-09-05 21:47:34 +000096{
97 if( _id > -1 )
98 {
99 char id[MaxTextExtent];
cristye8c25f92010-06-03 00:53:06 +0000100 sprintf(id,"%.20g",(double) _id);
cristy3ed852e2009-09-05 21:47:34 +0000101 DeleteImageRegistry( id );
102 }
103 _id = id_;
104}