Magick++
7.1.2-29
Convert, Edit, Or Compose Bitmap Images
Toggle main menu visibility
Loading...
Searching...
No Matches
Blob.cpp
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
#include <string.h>
20
21
Magick::Blob::Blob(
void
)
22
: _blobRef(new Magick::BlobRef(0,0))
23
{
24
}
25
26
Magick::Blob::Blob(
const
void
* data_,
const
size_t
length_)
27
: _blobRef(new Magick::BlobRef(data_, length_))
28
{
29
}
30
31
Magick::Blob::Blob(
const
Magick::Blob
& blob_)
32
: _blobRef(blob_._blobRef)
33
{
34
// Increase reference count
35
_blobRef->increase();
36
}
37
38
Magick::Blob::~Blob()
39
{
40
try
41
{
42
if
(_blobRef->decrease() == 0)
43
delete
_blobRef;
44
}
45
catch
(Magick::Exception&)
46
{
47
}
48
49
_blobRef=(Magick::BlobRef *) NULL;
50
}
51
52
Magick::Blob& Magick::Blob::operator=(
const
Magick::Blob& blob_)
53
{
54
if
(
this
!= &blob_)
55
{
56
blob_._blobRef->increase();
57
if
(_blobRef->decrease() == 0)
58
delete
_blobRef;
59
60
_blobRef=blob_._blobRef;
61
}
62
return
(*
this
);
63
}
64
65
void
Magick::Blob::base64(
const
std::string base64_)
66
{
67
size_t
68
length;
69
70
unsigned
char
71
*decoded;
72
73
decoded=Base64Decode(base64_.c_str(),&length);
74
75
if
(decoded)
76
updateNoCopy(
static_cast<
void
*
>
(decoded),length,
77
Magick::Blob::MallocAllocator);
78
}
79
80
std::string Magick::Blob::base64(
void
)
const
81
{
82
size_t
83
encoded_length;
84
85
char
86
*encoded;
87
88
std::string
89
result;
90
91
encoded_length=0;
92
encoded=Base64Encode(
static_cast<
const
unsigned
char
*
>
(data()),length(),
93
&encoded_length);
94
95
if
(encoded)
96
{
97
result=std::string(encoded,encoded_length);
98
encoded=(
char
*) RelinquishMagickMemory(encoded);
99
return
result;
100
}
101
102
return
(std::string());
103
}
104
105
const
void
* Magick::Blob::data(
void
)
const
106
{
107
return
(_blobRef->data);
108
}
109
110
size_t
Magick::Blob::length(
void
)
const
111
{
112
return
(_blobRef->length);
113
}
114
115
void
Magick::Blob::update(
const
void
* data_,
size_t
length_)
116
{
117
if
(_blobRef->decrease() == 0)
118
delete
_blobRef;
119
120
_blobRef=
new
Magick::BlobRef(data_,length_);
121
}
122
123
void
Magick::Blob::updateNoCopy(
void
* data_,
size_t
length_,
124
Magick::Blob::Allocator allocator_)
125
{
126
if
(_blobRef->decrease() == 0)
127
delete
_blobRef;
128
129
_blobRef=
new
Magick::BlobRef((
const
void
*) NULL,0);
130
_blobRef->data=data_;
131
_blobRef->length=length_;
132
_blobRef->allocator=allocator_;
133
}
134
Magick::Blob
Definition
Blob.h:23
Magick++
lib
Blob.cpp
Generated by
1.17.0