www/api/Magick++/ImageRef_8cpp_source.html
| Magick++ 7.1.0 |
ImageRef.cpp
Go to the documentation of this file.
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002
4 //
5 // Copyright @ 2014 ImageMagick Studio LLC, a non-profit organization
6 // dedicated to making software imaging solutions freely available.
7 //
8 // Implementation of ImageRef
9 //
10 // This is an internal implementation class.
11 //
12
13 #define MAGICKCORE_IMPLEMENTATION 1
14 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
15
16 #include "Magick++/ImageRef.h"
17 #include "Magick++/Exception.h"
18 #include "Magick++/Options.h"
19
20 Magick::ImageRef::ImageRef(void)
21 : _image(0),
22 _mutexLock(),
23 _options(new Options),
24 _refCount(1)
25 {
27 _image=AcquireImage(_options->imageInfo(),exceptionInfo);
28ThrowPPException(false);
29 }
30
31 Magick::ImageRef::ImageRef(MagickCore::Image *image_)
32 : _image(image_),
33 _mutexLock(),
34 _options(new Options),
35 _refCount(1)
36 {
37 }
38
39 Magick::ImageRef::~ImageRef(void)
40 {
41// Deallocate image
42if (_image != (MagickCore::Image*) NULL)
43 _image=DestroyImageList(_image);
44
45// Deallocate image options
46delete _options;
47 _options=(Options *) NULL;
48 }
49
50 size_t Magick::ImageRef::decrease()
51 {
52size_t
53 count;
54
55 _mutexLock.lock();
56if (_refCount == 0)
57 {
58 _mutexLock.unlock();
59throwExceptionExplicit(MagickCore::OptionError,
60"Invalid call to decrease");
61return(0);
62 }
63 count=--_refCount;
64 _mutexLock.unlock();
65return(count);
66 }
67
68 MagickCore::Image *&Magick::ImageRef::image(void)
69 {
70return(_image);
71 }
72
73 void Magick::ImageRef::increase()
74 {
75 _mutexLock.lock();
76 _refCount++;
77 _mutexLock.unlock();
78 }
79
80 bool Magick::ImageRef::isShared()
81 {
82bool
83 isShared;
84
85 _mutexLock.lock();
86 isShared=(_refCount > 1);
87 _mutexLock.unlock();
88return(isShared);
89 }
90
91 voidMagick::ImageRef::options(Magick::Options *options_)
92 {
93delete _options;
94 _options=options_;
95 }
96
97 Magick::Options *Magick::ImageRef::options(void)
98 {
99return(_options);
100 }
101
102 Magick::ImageRef *Magick::ImageRef::replaceImage(ImageRef *imgRef,
103MagickCore::Image *replacement_)
104 {
106 *instance;
107
108 imgRef->_mutexLock.lock();
109if (imgRef->_refCount == 1)
110 {
111// We can replace the image if we own it.
112 instance=imgRef;
113if (imgRef->_image != (MagickCore::Image*) NULL)
114 (void) DestroyImageList(imgRef->_image);
115 imgRef->_image=replacement_;
116 imgRef->_mutexLock.unlock();
117 }
118else
119 {
120// We don't own the image, create a new ImageRef instance.
121 instance=new ImageRef(replacement_,imgRef->_options);
122 imgRef->_refCount--;
123 imgRef->_mutexLock.unlock();
124 }
125return(instance);
126 }
127
128 std::string Magick::ImageRef::signature(const bool force_)
129 {
130const char
131 *property;
132
133// Re-calculate image signature if necessary
134GetPPException;
135 _mutexLock.lock();
136property=(const char *) NULL;
137if (!force_ && (_image->taint == MagickFalse))
138 property=GetImageProperty(_image,"Signature",exceptionInfo);
139if (property == (const char *) NULL)
140 {
141 (void) SignatureImage(_image,exceptionInfo);
142property=GetImageProperty(_image,"Signature",exceptionInfo);
143 }
144 _mutexLock.unlock();
145ThrowPPException(true);
146
147return(std::string(property));
148 }
149
150 Magick::ImageRef::ImageRef(MagickCore::Image *image_,const Options *options_)
151 : _image(image_),
152 _mutexLock(),
153 _options(0),
154 _refCount(1)
155 {
156 _options=new Options(*options_);
157 }
Definition: Options.h:30
MagickCore::ImageInfo * imageInfo(void)
Definition: Options.cpp:950
Definition: ImageRef.h:28
void unlock(void)
Definition: Thread.cpp:97
size_t decrease()
Definition: ImageRef.cpp:50
void lock(void)
Definition: Thread.cpp:78
Options * options(void)
Definition: ImageRef.cpp:97
Magick::throwExceptionExplicit
MagickPPExport void throwExceptionExplicit(const MagickCore::ExceptionType severity_, const char *reason_, const char *description_=(char *) NULL)
Definition: Exception.cpp:808
#define ThrowPPException(quiet)
Definition: Include.h:1580
void increase()
Definition: ImageRef.cpp:73
Magick::ImageRef::replaceImage
static ImageRef * replaceImage(ImageRef *imgRef, MagickCore::Image *replacement_)
Definition: ImageRef.cpp:102
bool isShared()
Definition: ImageRef.cpp:80
class MagickPPExport Image
Definition: Drawable.h:722
ImageRef(void)
Definition: ImageRef.cpp:20
MagickCore::Image *& image(void)
Definition: ImageRef.cpp:68
#define GetPPException
Definition: Include.h:1561
~ImageRef(void)
Definition: ImageRef.cpp:39
std::string signature(const bool force_=false)
Definition: ImageRef.cpp:128