Coverage Report

Created: 2025-06-16 07:00

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