Magick++
7.1.2-32
Convert, Edit, Or Compose Bitmap Images
Toggle main menu visibility
Loading...
Searching...
No Matches
BlobRef.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 @ 2014 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++/BlobRef.h"
16
#include "Magick++/Exception.h"
17
#include "Magick++/Thread.h"
18
#include <cstring>
19
20
Magick::BlobRef::BlobRef(
const
void
* data_,
const
size_t
length_)
21
: allocator(Magick::Blob::NewAllocator),
22
length(length_),
23
data((void*) NULL),
24
_mutexLock(),
25
_refCount(1)
26
{
27
if
(data_ != (
const
void
*) NULL)
28
{
29
data=
new
unsigned
char
[length_];
30
memcpy(data,data_,length_);
31
}
32
}
33
34
Magick::BlobRef::~BlobRef(
void
)
35
{
36
if
(allocator == Magick::Blob::NewAllocator)
37
{
38
delete
[]
static_cast<
unsigned
char
*
>
(data);
39
data=(
void
*) NULL;
40
}
41
else
if
(allocator == Magick::Blob::MallocAllocator)
42
data=(
void
*) RelinquishMagickMemory(data);
43
}
44
45
size_t
Magick::BlobRef::decrease()
46
{
47
size_t
48
count;
49
50
_mutexLock.lock();
51
if
(_refCount == 0)
52
{
53
_mutexLock.unlock();
54
throwExceptionExplicit(MagickCore::OptionError,
55
"Invalid call to decrease"
);
56
return
(0);
57
}
58
count=--_refCount;
59
_mutexLock.unlock();
60
return
(count);
61
}
62
63
void
Magick::BlobRef::increase()
64
{
65
_mutexLock.lock();
66
_refCount++;
67
_mutexLock.unlock();
68
}
Magick++
lib
BlobRef.cpp
Generated by
1.18.0