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