/src/imagemagick/Magick++/lib/Blob.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, 2004 |
4 | | // |
5 | | // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization |
6 | | // dedicated to making software imaging solutions freely available. |
7 | | // |
8 | | // Implementation of Blob |
9 | | // |
10 | | |
11 | | #define MAGICKCORE_IMPLEMENTATION 1 |
12 | | #define MAGICK_PLUSPLUS_IMPLEMENTATION 1 |
13 | | |
14 | | #include "Magick++/Include.h" |
15 | | #include "Magick++/Blob.h" |
16 | | #include "Magick++/BlobRef.h" |
17 | | #include "Magick++/Exception.h" |
18 | | |
19 | | Magick::Blob::Blob(void) |
20 | 61.5k | : _blobRef(new Magick::BlobRef(0,0)) |
21 | 61.5k | { |
22 | 61.5k | } |
23 | | |
24 | | Magick::Blob::Blob(const void* data_,const size_t length_) |
25 | 570k | : _blobRef(new Magick::BlobRef(data_, length_)) |
26 | 570k | { |
27 | 570k | } |
28 | | |
29 | | Magick::Blob::Blob(const Magick::Blob& blob_) |
30 | 0 | : _blobRef(blob_._blobRef) |
31 | 0 | { |
32 | | // Increase reference count |
33 | 0 | _blobRef->increase(); |
34 | 0 | } |
35 | | |
36 | | Magick::Blob::~Blob() |
37 | 632k | { |
38 | 632k | try |
39 | 632k | { |
40 | 632k | if (_blobRef->decrease() == 0) |
41 | 632k | delete _blobRef; |
42 | 632k | } |
43 | 632k | catch(Magick::Exception&) |
44 | 632k | { |
45 | 0 | } |
46 | | |
47 | 632k | _blobRef=(Magick::BlobRef *) NULL; |
48 | 632k | } |
49 | | |
50 | | Magick::Blob& Magick::Blob::operator=(const Magick::Blob& blob_) |
51 | 0 | { |
52 | 0 | if (this != &blob_) |
53 | 0 | { |
54 | 0 | blob_._blobRef->increase(); |
55 | 0 | if (_blobRef->decrease() == 0) |
56 | 0 | delete _blobRef; |
57 | | |
58 | 0 | _blobRef=blob_._blobRef; |
59 | 0 | } |
60 | 0 | return(*this); |
61 | 0 | } |
62 | | |
63 | | void Magick::Blob::base64(const std::string base64_) |
64 | 0 | { |
65 | 0 | size_t |
66 | 0 | length; |
67 | |
|
68 | 0 | unsigned char |
69 | 0 | *decoded; |
70 | |
|
71 | 0 | decoded=Base64Decode(base64_.c_str(),&length); |
72 | |
|
73 | 0 | if(decoded) |
74 | 0 | updateNoCopy(static_cast<void*>(decoded),length, |
75 | 0 | Magick::Blob::MallocAllocator); |
76 | 0 | } |
77 | | |
78 | | std::string Magick::Blob::base64(void) const |
79 | 0 | { |
80 | 0 | size_t |
81 | 0 | encoded_length; |
82 | |
|
83 | 0 | char |
84 | 0 | *encoded; |
85 | |
|
86 | 0 | std::string |
87 | 0 | result; |
88 | |
|
89 | 0 | encoded_length=0; |
90 | 0 | encoded=Base64Encode(static_cast<const unsigned char*>(data()),length(), |
91 | 0 | &encoded_length); |
92 | |
|
93 | 0 | if(encoded) |
94 | 0 | { |
95 | 0 | result=std::string(encoded,encoded_length); |
96 | 0 | encoded=(char *) RelinquishMagickMemory(encoded); |
97 | 0 | return result; |
98 | 0 | } |
99 | | |
100 | 0 | return(std::string()); |
101 | 0 | } |
102 | | |
103 | | const void* Magick::Blob::data(void) const |
104 | 570k | { |
105 | 570k | return(_blobRef->data); |
106 | 570k | } |
107 | | |
108 | | size_t Magick::Blob::length(void) const |
109 | 570k | { |
110 | 570k | return(_blobRef->length); |
111 | 570k | } |
112 | | |
113 | | void Magick::Blob::update(const void* data_,size_t length_) |
114 | 0 | { |
115 | 0 | if (_blobRef->decrease() == 0) |
116 | 0 | delete _blobRef; |
117 | |
|
118 | 0 | _blobRef=new Magick::BlobRef(data_,length_); |
119 | 0 | } |
120 | | |
121 | | void Magick::Blob::updateNoCopy(void* data_,size_t length_, |
122 | | Magick::Blob::Allocator allocator_) |
123 | 61.2k | { |
124 | 61.2k | if (_blobRef->decrease() == 0) |
125 | 61.2k | delete _blobRef; |
126 | | |
127 | | _blobRef=new Magick::BlobRef((const void*) NULL,0); |
128 | 61.2k | _blobRef->data=data_; |
129 | 61.2k | _blobRef->length=length_; |
130 | 61.2k | _blobRef->allocator=allocator_; |
131 | 61.2k | } |
132 | | |