1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2004
4 // Copyright Dirk Lemstra 2013-2017
6 // Implementation of Blob
9 #define MAGICKCORE_IMPLEMENTATION 1
10 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
12 #include "Magick++/Include.h"
13 #include "Magick++/Blob.h"
14 #include "Magick++/BlobRef.h"
15 #include "Magick++/Exception.h"
19 Magick::Blob::Blob(void)
20 : _blobRef(new Magick::BlobRef(0,0))
24 Magick::Blob::Blob(const void* data_,const size_t length_)
25 : _blobRef(new Magick::BlobRef(data_, length_))
29 Magick::Blob::Blob(const Magick::Blob& blob_)
30 : _blobRef(blob_._blobRef)
32 // Increase reference count
40 if (_blobRef->decrease() == 0)
43 catch(Magick::Exception&)
47 _blobRef=(Magick::BlobRef *) NULL;
50 Magick::Blob& Magick::Blob::operator=(const Magick::Blob& blob_)
54 blob_._blobRef->increase();
55 if (_blobRef->decrease() == 0)
58 _blobRef=blob_._blobRef;
63 void Magick::Blob::base64(const std::string base64_)
71 decoded=Base64Decode(base64_.c_str(),&length);
74 updateNoCopy(static_cast<void*>(decoded),length,
75 Magick::Blob::MallocAllocator);
78 std::string Magick::Blob::base64(void) const
90 encoded=Base64Encode(static_cast<const unsigned char*>(data()),length(),
95 result=std::string(encoded,encoded_length);
96 encoded=(char *) RelinquishMagickMemory(encoded);
100 return(std::string());
103 const void* Magick::Blob::data(void) const
105 return(_blobRef->data);
108 size_t Magick::Blob::length(void) const
110 return(_blobRef->length);
113 void Magick::Blob::update(const void* data_,size_t length_)
115 if (_blobRef->decrease() == 0)
118 _blobRef=new Magick::BlobRef(data_,length_);
121 void Magick::Blob::updateNoCopy(void* data_,size_t length_,
122 Magick::Blob::Allocator allocator_)
124 if (_blobRef->decrease() == 0)
127 _blobRef=new Magick::BlobRef((const void*) NULL,0);
128 _blobRef->data=data_;
129 _blobRef->length=length_;
130 _blobRef->allocator=allocator_;