1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2004
5 // Implementation of Blob
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11 #include "Magick++/Include.h"
12 #include "Magick++/Blob.h"
13 #include "Magick++/BlobRef.h"
17 Magick::Blob::Blob(void)
18 : _blobRef(new Magick::BlobRef(0,0))
22 Magick::Blob::Blob(const void* data_,size_t length_)
23 : _blobRef(new Magick::BlobRef(data_, length_))
27 Magick::Blob::Blob(const Magick::Blob& blob_)
28 : _blobRef(blob_._blobRef)
30 // Increase reference count
31 Lock(&_blobRef->mutexLock);
42 Lock(&_blobRef->mutexLock);
43 if (--_blobRef->refCount == 0)
49 // Delete old blob reference with associated data
55 Magick::Blob& Magick::Blob::operator=(const Magick::Blob& blob_)
63 Lock(&blob_._blobRef->mutexLock);
64 ++blob_._blobRef->refCount;
68 Lock(&_blobRef->mutexLock);
69 if (--_blobRef->refCount == 0)
76 _blobRef=blob_._blobRef;
81 void Magick::Blob::base64(const std::string base64_)
89 decoded=Base64Decode(base64_.c_str(),&length);
92 updateNoCopy(static_cast<void*>(decoded),length,
93 Magick::Blob::MallocAllocator);
96 std::string Magick::Blob::base64(void) const
108 encoded=Base64Encode(static_cast<const unsigned char*>(data()),length(),
113 result=std::string(encoded,encoded_length);
114 encoded=(char *) RelinquishMagickMemory(encoded);
118 return(std::string());
121 const void* Magick::Blob::data(void) const
123 return(_blobRef->data);
126 size_t Magick::Blob::length(void) const
128 return(_blobRef->length);
131 void Magick::Blob::update(const void* data_,size_t length_)
138 Lock(&_blobRef->mutexLock);
139 if (--_blobRef->refCount == 0)
144 // Delete old blob reference with associated data
148 _blobRef=new Magick::BlobRef(data_,length_);
151 void Magick::Blob::updateNoCopy(void* data_,size_t length_,
152 Magick::Blob::Allocator allocator_)
159 Lock(&_blobRef->mutexLock);
160 if (--_blobRef->refCount == 0)
165 // Delete old blob reference with associated data
168 _blobRef=new Magick::BlobRef(0,0);
169 _blobRef->data=data_;
170 _blobRef->length=length_;
171 _blobRef->allocator=allocator_;