Coverage Report

Created: 2026-09-06 07:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmwaw/src/lib/MWAWPictBitmap.hxx
Line
Count
Source
1
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3
/* libmwaw
4
* Version: MPL 2.0 / LGPLv2+
5
*
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 2.0 (the "License"); you may not use this file except in compliance with
8
* the License or as specified alternatively below. You may obtain a copy of
9
* the License at http://www.mozilla.org/MPL/
10
*
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
14
* License.
15
*
16
* Major Contributor(s):
17
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20
* Copyright (C) 2006, 2007 Andrew Ziem
21
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22
*
23
*
24
* All Rights Reserved.
25
*
26
* For minor contributions see the git repository.
27
*
28
* Alternatively, the contents of this file may be used under the terms of
29
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30
* in which case the provisions of the LGPLv2+ are applicable
31
* instead of those above.
32
*/
33
34
/* This header contains code specific to some bitmap
35
 */
36
37
#ifndef MWAW_PICT_BITMAP
38
#  define MWAW_PICT_BITMAP
39
40
41
#include <limits>
42
#include <vector>
43
44
#include "libmwaw_internal.hxx"
45
#include "MWAWDebug.hxx"
46
#include "MWAWPict.hxx"
47
48
////////////////////////////////////////////////////////////
49
//
50
//   Some container
51
//
52
////////////////////////////////////////////////////////////
53
54
/** \brief a template class to store a 2D array of m_data */
55
template <class T> class MWAWPictBitmapContainer
56
{
57
public:
58
  //! constructor given size
59
  explicit MWAWPictBitmapContainer(MWAWVec2i const &sz)
60
2.74M
    : m_size(sz)
61
2.74M
    , m_data(nullptr)
62
2.74M
  {
63
2.74M
    if (m_size[0]<=0 || m_size[1]<=0 || m_size[0]>(std::numeric_limits<int>::max)()/m_size[1]) return;
64
2.73M
    size_t const numElements=size_t(m_size[0])*size_t(m_size[1]);
65
2.73M
    m_data = new T[numElements];
66
2.73M
    std::uninitialized_fill_n(m_data, numElements, T());
67
2.73M
  }
MWAWPictBitmapContainer<int>::MWAWPictBitmapContainer(MWAWVec2<int> const&)
Line
Count
Source
60
2.62M
    : m_size(sz)
61
2.62M
    , m_data(nullptr)
62
2.62M
  {
63
2.62M
    if (m_size[0]<=0 || m_size[1]<=0 || m_size[0]>(std::numeric_limits<int>::max)()/m_size[1]) return;
64
2.62M
    size_t const numElements=size_t(m_size[0])*size_t(m_size[1]);
65
2.62M
    m_data = new T[numElements];
66
2.62M
    std::uninitialized_fill_n(m_data, numElements, T());
67
2.62M
  }
MWAWPictBitmapContainer<bool>::MWAWPictBitmapContainer(MWAWVec2<int> const&)
Line
Count
Source
60
3.90k
    : m_size(sz)
61
3.90k
    , m_data(nullptr)
62
3.90k
  {
63
3.90k
    if (m_size[0]<=0 || m_size[1]<=0 || m_size[0]>(std::numeric_limits<int>::max)()/m_size[1]) return;
64
3.68k
    size_t const numElements=size_t(m_size[0])*size_t(m_size[1]);
65
3.68k
    m_data = new T[numElements];
66
3.68k
    std::uninitialized_fill_n(m_data, numElements, T());
67
3.68k
  }
MWAWPictBitmapContainer<MWAWColor>::MWAWPictBitmapContainer(MWAWVec2<int> const&)
Line
Count
Source
60
110k
    : m_size(sz)
61
110k
    , m_data(nullptr)
62
110k
  {
63
110k
    if (m_size[0]<=0 || m_size[1]<=0 || m_size[0]>(std::numeric_limits<int>::max)()/m_size[1]) return;
64
100k
    size_t const numElements=size_t(m_size[0])*size_t(m_size[1]);
65
100k
    m_data = new T[numElements];
66
100k
    std::uninitialized_fill_n(m_data, numElements, T());
67
100k
  }
68
  //! destructor
69
  virtual ~MWAWPictBitmapContainer()
70
2.74M
  {
71
2.74M
    if (m_data) delete [] m_data;
72
2.74M
  }
MWAWPictBitmapContainer<int>::~MWAWPictBitmapContainer()
Line
Count
Source
70
2.62M
  {
71
2.62M
    if (m_data) delete [] m_data;
72
2.62M
  }
MWAWPictBitmapContainer<bool>::~MWAWPictBitmapContainer()
Line
Count
Source
70
3.90k
  {
71
3.90k
    if (m_data) delete [] m_data;
72
3.90k
  }
MWAWPictBitmapContainer<MWAWColor>::~MWAWPictBitmapContainer()
Line
Count
Source
70
110k
  {
71
110k
    if (m_data) delete [] m_data;
72
110k
  }
73
74
  //! returns ok, if the m_data is allocated
75
  bool ok() const
76
2.74M
  {
77
2.74M
    return (m_data != nullptr);
78
2.74M
  }
MWAWPictBitmapContainer<bool>::ok() const
Line
Count
Source
76
6.75k
  {
77
6.75k
    return (m_data != nullptr);
78
6.75k
  }
MWAWPictBitmapContainer<int>::ok() const
Line
Count
Source
76
2.62M
  {
77
2.62M
    return (m_data != nullptr);
78
2.62M
  }
MWAWPictBitmapContainer<MWAWColor>::ok() const
Line
Count
Source
76
110k
  {
77
110k
    return (m_data != nullptr);
78
110k
  }
79
80
  //! a comparison operator
81
  int cmp(MWAWPictBitmapContainer<T> const &orig) const
82
0
  {
83
0
    int diff = m_size.cmpY(orig.m_size);
84
0
    if (diff) return diff;
85
0
    if (!m_data) return orig.m_data ? 1 : 0;
86
0
    if (!orig.m_data) return -1;
87
0
    for (int i=0; i < m_size[0]*m_size[1]; i++) {
88
0
      if (m_data[i] < orig.m_data[i]) return -1;
89
0
      if (m_data[i] > orig.m_data[i]) return 1;
90
0
    }
91
0
    return 0;
92
0
  }
Unexecuted instantiation: MWAWPictBitmapContainer<int>::cmp(MWAWPictBitmapContainer<int> const&) const
Unexecuted instantiation: MWAWPictBitmapContainer<MWAWColor>::cmp(MWAWPictBitmapContainer<MWAWColor> const&) const
93
  //! return the array size
94
  MWAWVec2i const &size() const
95
2.72M
  {
96
2.72M
    return m_size;
97
2.72M
  }
MWAWPictBitmapContainer<bool>::size() const
Line
Count
Source
95
3.60k
  {
96
3.60k
    return m_size;
97
3.60k
  }
MWAWPictBitmapContainer<int>::size() const
Line
Count
Source
95
2.62M
  {
96
2.62M
    return m_size;
97
2.62M
  }
MWAWPictBitmapContainer<MWAWColor>::size() const
Line
Count
Source
95
99.5k
  {
96
99.5k
    return m_size;
97
99.5k
  }
98
  //! gets the number of row
99
  int numRows() const
100
0
  {
101
0
    return m_size[0];
102
0
  }
Unexecuted instantiation: MWAWPictBitmapContainer<bool>::numRows() const
Unexecuted instantiation: MWAWPictBitmapContainer<int>::numRows() const
Unexecuted instantiation: MWAWPictBitmapContainer<MWAWColor>::numRows() const
103
  //! gets the number of column
104
  int numColumns() const
105
0
  {
106
0
    return m_size[1];
107
0
  }
Unexecuted instantiation: MWAWPictBitmapContainer<bool>::numColumns() const
Unexecuted instantiation: MWAWPictBitmapContainer<int>::numColumns() const
Unexecuted instantiation: MWAWPictBitmapContainer<MWAWColor>::numColumns() const
108
109
  //! accessor of a cell m_data
110
  T const &get(int i, int j) const
111
0
  {
112
0
    if (m_data == nullptr || i<0 || i >= m_size[0] || j<0 || j >= m_size[1])
113
0
      throw libmwaw::GenericException();
114
0
    return m_data[i+m_size[0]*j];
115
0
  }
Unexecuted instantiation: MWAWPictBitmapContainer<bool>::get(int, int) const
Unexecuted instantiation: MWAWPictBitmapContainer<int>::get(int, int) const
Unexecuted instantiation: MWAWPictBitmapContainer<MWAWColor>::get(int, int) const
116
  //! accessor of a row m_data
117
  T const *getRow(int j) const
118
24.0M
  {
119
24.0M
    if (m_data == nullptr || j<0 || j >= m_size[1])
120
0
      throw libmwaw::GenericException();
121
24.0M
    return m_data+m_size[0]*j;
122
24.0M
  }
MWAWPictBitmapContainer<bool>::getRow(int) const
Line
Count
Source
118
1.92M
  {
119
1.92M
    if (m_data == nullptr || j<0 || j >= m_size[1])
120
0
      throw libmwaw::GenericException();
121
1.92M
    return m_data+m_size[0]*j;
122
1.92M
  }
MWAWPictBitmapContainer<int>::getRow(int) const
Line
Count
Source
118
21.3M
  {
119
21.3M
    if (m_data == nullptr || j<0 || j >= m_size[1])
120
0
      throw libmwaw::GenericException();
121
21.3M
    return m_data+m_size[0]*j;
122
21.3M
  }
MWAWPictBitmapContainer<MWAWColor>::getRow(int) const
Line
Count
Source
118
723k
  {
119
723k
    if (m_data == nullptr || j<0 || j >= m_size[1])
120
0
      throw libmwaw::GenericException();
121
723k
    return m_data+m_size[0]*j;
122
723k
  }
123
124
  //! sets a cell m_data
125
  void set(int i, int j, T const &v)
126
200M
  {
127
200M
    if (m_data == nullptr || i<0 || i >= m_size[0] || j<0 || j >= m_size[1]) {
128
194k
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::set: call with bad coordinate %d %d\n", i, j));
129
194k
      return;
130
194k
    }
131
200M
    m_data[i+j*m_size[0]] = v;
132
200M
  }
MWAWPictBitmapContainer<int>::set(int, int, int const&)
Line
Count
Source
126
132M
  {
127
132M
    if (m_data == nullptr || i<0 || i >= m_size[0] || j<0 || j >= m_size[1]) {
128
194k
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::set: call with bad coordinate %d %d\n", i, j));
129
194k
      return;
130
194k
    }
131
132M
    m_data[i+j*m_size[0]] = v;
132
132M
  }
Unexecuted instantiation: MWAWPictBitmapContainer<bool>::set(int, int, bool const&)
MWAWPictBitmapContainer<MWAWColor>::set(int, int, MWAWColor const&)
Line
Count
Source
126
67.9M
  {
127
67.9M
    if (m_data == nullptr || i<0 || i >= m_size[0] || j<0 || j >= m_size[1]) {
128
0
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::set: call with bad coordinate %d %d\n", i, j));
129
0
      return;
130
0
    }
131
67.9M
    m_data[i+j*m_size[0]] = v;
132
67.9M
  }
133
134
  //! sets a line of m_data
135
  template <class U>
136
  void setRow(int j, U const *val)
137
21.6M
  {
138
21.6M
    if (m_data == nullptr || j<0 || j >= m_size[1]) {
139
235k
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::setRow: call with bad coordinate %d\n", j));
140
235k
      return;
141
235k
    }
142
565M
    for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
143
21.4M
  }
Unexecuted instantiation: void MWAWPictBitmapContainer<bool>::setRow<bool>(int, bool const*)
void MWAWPictBitmapContainer<MWAWColor>::setRow<MWAWColor>(int, MWAWColor const*)
Line
Count
Source
137
701k
  {
138
701k
    if (m_data == nullptr || j<0 || j >= m_size[1]) {
139
235k
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::setRow: call with bad coordinate %d\n", j));
140
235k
      return;
141
235k
    }
142
376M
    for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
143
465k
  }
void MWAWPictBitmapContainer<int>::setRow<int>(int, int const*)
Line
Count
Source
137
20.9M
  {
138
20.9M
    if (m_data == nullptr || j<0 || j >= m_size[1]) {
139
0
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::setRow: call with bad coordinate %d\n", j));
140
0
      return;
141
0
    }
142
188M
    for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
143
20.9M
  }
Unexecuted instantiation: void MWAWPictBitmapContainer<int>::setRow<unsigned char>(int, unsigned char const*)
144
145
  //! sets a column of m_data
146
  template <class U>
147
  void setColumn(int i, U const *val)
148
0
  {
149
0
    if (m_data == nullptr || i<0 || i >= m_size[0]) {
150
0
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::setColumn: call with bad coordinate %d\n", i));
151
0
      return;
152
0
    }
153
0
    for (int j = 0, ind=i; j < m_size[1]; j++, ind+=m_size[0]) m_data[ind] = T(val[i]);
154
0
  }
Unexecuted instantiation: void MWAWPictBitmapContainer<bool>::setColumn<bool>(int, bool const*)
Unexecuted instantiation: void MWAWPictBitmapContainer<MWAWColor>::setColumn<MWAWColor>(int, MWAWColor const*)
155
156
private:
157
  MWAWPictBitmapContainer(MWAWPictBitmapContainer const &orig) = delete;
158
  MWAWPictBitmapContainer &operator=(MWAWPictBitmapContainer const &orig) = delete;
159
protected:
160
  //! the size
161
  MWAWVec2i m_size;
162
  //! the m_data placed by row ie. d_00, d_10, ... , d_{X-1}0, ..
163
  T *m_data;
164
};
165
166
//! a bool container with a function to put packed row
167
class MWAWPictBitmapContainerBool final : public MWAWPictBitmapContainer<bool>
168
{
169
public:
170
  //! constructor
171
  explicit MWAWPictBitmapContainerBool(MWAWVec2i const &sz)
172
3.90k
    : MWAWPictBitmapContainer<bool>(sz)
173
3.90k
  {
174
3.90k
  }
175
  //! destructor
176
  ~MWAWPictBitmapContainerBool() final;
177
  //! a comparison operator
178
  int cmp(MWAWPictBitmapContainerBool const &orig) const
179
0
  {
180
0
    int diff = m_size.cmpY(orig.m_size);
181
0
    if (diff) return diff;
182
0
    if (!m_data) return orig.m_data ? 1 : 0;
183
0
    if (!orig.m_data) return -1;
184
0
    for (int i=0; i < m_size[0]*m_size[1]; i++) {
185
0
      if (m_data[i] == orig.m_data[i]) continue;
186
0
      return m_data[i] ? 1 : -1;
187
0
    }
188
0
    return 0;
189
0
  }
190
191
  //! allows to use packed m_data
192
  void setRowPacked(int j, unsigned char const *val, unsigned char const *end)
193
1.92M
  {
194
1.92M
    if (m_data == nullptr || j<0 || j >= m_size[1] || val >= end) {
195
5.67k
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainerBool::setRowPacked: call with bad coordinate %d\n", j));
196
5.67k
      return;
197
5.67k
    }
198
5.96M
    for (int i = 0, ind = j*m_size[0]; i < m_size[0];) {
199
4.04M
      unsigned char v = (val < end) ? *(val++) : 0;
200
4.04M
      unsigned char mask = 0x80;
201
29.7M
      for (int p = 0; p < 8 && i < m_size[0]; i++, p++, ind++) {
202
25.7M
        m_data[ind] = ((v&mask) != 0);
203
25.7M
        mask = static_cast<unsigned char>(mask >> 1);
204
25.7M
      }
205
4.04M
    }
206
1.92M
  }
207
};
208
209
//! Generic class used to construct bitmap
210
class MWAWPictBitmap : public MWAWPict
211
{
212
public:
213
  //! destructor
214
  ~MWAWPictBitmap() override;
215
216
  //! the picture subtype: blackwhite, indexed, color
217
  enum SubType { BW, Indexed, Color };
218
  //! returns the picture type
219
  Type getType() const override
220
0
  {
221
0
    return MWAWPict::Bitmap;
222
0
  }
223
  //! returns the picture subtype
224
  virtual SubType getSubType() const = 0;
225
226
  //! returns the final picture
227
  bool getBinary(MWAWEmbeddedObject &picture) const override
228
2.73M
  {
229
2.73M
    if (!valid()) return false;
230
231
2.72M
    librevenge::RVNGBinaryData data;
232
2.72M
    createFileData(data);
233
2.72M
    picture=MWAWEmbeddedObject(data, "image/pict");
234
2.72M
    return true;
235
2.73M
  }
236
237
  //! returns true if the picture is valid
238
  virtual bool valid() const
239
0
  {
240
0
    return false;
241
0
  }
242
243
  //! returns the average color
244
  virtual MWAWColor getAverageColor() const = 0;
245
  /** a virtual function used to obtain a strict order,
246
  must be redefined in the subs class */
247
  int cmp(MWAWPict const &a) const override
248
0
  {
249
0
    int diff = MWAWPict::cmp(a);
250
0
    if (diff) return diff;
251
0
    auto const &aPict = static_cast<MWAWPictBitmap const &>(a);
252
253
    // the type
254
0
    diff = getSubType() - aPict.getSubType();
255
0
    if (diff) return (diff < 0) ? -1 : 1;
256
257
0
    return 0;
258
0
  }
259
260
protected:
261
  //! abstract function which creates the result file
262
  virtual bool createFileData(librevenge::RVNGBinaryData &result) const = 0;
263
264
  //! protected constructor: use check to construct a picture
265
  explicit MWAWPictBitmap(MWAWVec2i const &sz)
266
2.74M
  {
267
2.74M
    setBdBox(MWAWBox2f(MWAWVec2f(0,0), MWAWVec2f(sz)));
268
2.74M
  }
269
};
270
271
/** a bitmap of bool to store black-white bitmap */
272
class MWAWPictBitmapBW final : public MWAWPictBitmap
273
{
274
public:
275
  //! returns the picture subtype
276
  SubType getSubType() const final
277
0
  {
278
0
    return BW;
279
0
  }
280
281
  /** a virtual function used to obtain a strict order,
282
  must be redefined in the subs class */
283
  int cmp(MWAWPict const &a) const final
284
0
  {
285
0
    int diff = MWAWPictBitmap::cmp(a);
286
0
    if (diff) return diff;
287
0
    auto const &aPict = static_cast<MWAWPictBitmapBW const &>(a);
288
289
0
    return m_data.cmp(aPict.m_data);
290
0
  }
291
292
  //! returns true if the picture is valid
293
  bool valid() const final
294
6.75k
  {
295
6.75k
    return m_data.ok();
296
6.75k
  }
297
298
  //! the constructor
299
  explicit MWAWPictBitmapBW(MWAWVec2i const &sz)
300
3.90k
    : MWAWPictBitmap(sz)
301
3.90k
    , m_data(sz)
302
3.90k
  {
303
3.90k
  }
304
305
  //! the picture size
306
  MWAWVec2i const &size() const
307
0
  {
308
0
    return m_data.size();
309
0
  }
310
  //! the number of rows
311
  int numRows() const
312
0
  {
313
0
    return m_data.numRows();
314
0
  }
315
  //! the number of columns
316
  int numColumns() const
317
0
  {
318
0
    return m_data.numColumns();
319
0
  }
320
  //! returns a cell content
321
  bool get(int i, int j) const
322
0
  {
323
0
    return m_data.get(i,j);
324
0
  }
325
  //! returns the cells content of a row
326
  bool const *getRow(int j) const
327
0
  {
328
0
    return m_data.getRow(j);
329
0
  }
330
  //! sets a cell contents
331
  void set(int i, int j, bool v)
332
0
  {
333
0
    m_data.set(i,j, v);
334
0
  }
335
  //! sets all cell contents of a row
336
  void setRow(int j, bool const *val)
337
0
  {
338
0
    m_data.setRow(j, val);
339
0
  }
340
  //! sets all cell contents of a row given packed m_data
341
  void setRowPacked(int j, unsigned char const *val, unsigned char const *end)
342
1.92M
  {
343
1.92M
    m_data.setRowPacked(j, val, end);
344
1.92M
  }
345
  //! sets all cell contents of a column
346
  void setColumn(int i, bool const *val)
347
0
  {
348
0
    m_data.setColumn(i, val);
349
0
  }
350
  //! returns the average color
351
  MWAWColor getAverageColor() const final;
352
353
protected:
354
  //! function which creates the result file
355
  bool createFileData(librevenge::RVNGBinaryData &result) const final;
356
357
  //! the data
358
  MWAWPictBitmapContainerBool m_data;
359
};
360
361
/** a bitmap of int to store indexed bitmap */
362
class MWAWPictBitmapIndexed final : public MWAWPictBitmap
363
{
364
public:
365
  //! return the picture subtype
366
  SubType getSubType() const final
367
0
  {
368
0
    return Indexed;
369
0
  }
370
371
  /** a virtual function used to obtain a strict order,
372
  must be redefined in the subs class */
373
  int cmp(MWAWPict const &a) const final
374
0
  {
375
0
    int diff = MWAWPictBitmap::cmp(a);
376
0
    if (diff) return diff;
377
0
    auto const &aPict = static_cast<MWAWPictBitmapIndexed const &>(a);
378
379
0
    diff=int(m_colors.size())-int(aPict.m_colors.size());
380
0
    if (diff) return (diff < 0) ? -1 : 1;
381
0
    for (size_t c=0; c < m_colors.size(); c++) {
382
0
      if (m_colors[c] < aPict.m_colors[c])
383
0
        return 1;
384
0
      if (m_colors[c] > aPict.m_colors[c])
385
0
        return -1;
386
0
    }
387
0
    return m_data.cmp(aPict.m_data);
388
0
  }
389
390
  //! returns true if the picture is valid
391
  bool valid() const final
392
2.62M
  {
393
2.62M
    return m_data.ok();
394
2.62M
  }
395
  //! returns the average color
396
  MWAWColor getAverageColor() const final;
397
398
  //! the constructor
399
  explicit MWAWPictBitmapIndexed(MWAWVec2i const &sz)
400
2.62M
    : MWAWPictBitmap(sz)
401
2.62M
    , m_data(sz)
402
2.62M
    , m_colors()
403
2.62M
  {
404
2.62M
  }
405
406
  //! the picture size
407
  MWAWVec2i const &size() const
408
0
  {
409
0
    return m_data.size();
410
0
  }
411
  //! the number of rows
412
  int numRows() const
413
0
  {
414
0
    return m_data.numRows();
415
0
  }
416
  //! the number of columns
417
  int numColumns() const
418
0
  {
419
0
    return m_data.numColumns();
420
0
  }
421
  //! returns a cell content
422
  int get(int i, int j) const
423
0
  {
424
0
    return m_data.get(i,j);
425
0
  }
426
  //! returns the cells content of a row
427
  int const *getRow(int j) const
428
0
  {
429
0
    return m_data.getRow(j);
430
0
  }
431
432
  //! sets a cell contents
433
  void set(int i, int j, int v)
434
132M
  {
435
132M
    m_data.set(i,j, v);
436
132M
  }
437
  //! sets all cell contents of a row
438
  template <class U> void setRow(int j, U const *val)
439
20.9M
  {
440
20.9M
    m_data.setRow(j, val);
441
20.9M
  }
void MWAWPictBitmapIndexed::setRow<int>(int, int const*)
Line
Count
Source
439
20.9M
  {
440
20.9M
    m_data.setRow(j, val);
441
20.9M
  }
Unexecuted instantiation: void MWAWPictBitmapIndexed::setRow<unsigned char>(int, unsigned char const*)
442
  //! sets all cell contents of a column
443
  template <class U> void setColumn(int i, U const *val)
444
  {
445
    m_data.setColumn(i, val);
446
  }
447
448
  //! returns the array of indexed colors
449
  std::vector<MWAWColor> const &getColors() const
450
0
  {
451
0
    return m_colors;
452
0
  }
453
  //! sets the array of indexed colors
454
  void setColors(std::vector<MWAWColor> const &cols)
455
2.62M
  {
456
2.62M
    m_colors = cols;
457
2.62M
  }
458
459
protected:
460
  //! the function which creates the result file
461
  bool createFileData(librevenge::RVNGBinaryData &result) const final;
462
463
  //! the m_data
464
  MWAWPictBitmapContainer<int> m_data;
465
  //! the colors
466
  std::vector<MWAWColor> m_colors;
467
};
468
469
/** a bitmap of MWAWColor to store true color bitmap
470
471
    \note: this class is actually the only class which can create
472
    bitmap with transparency (by creating a BMP), but as
473
    LibreOffice/OpenOffice seem to ignore the alpha channel when
474
    importing BMP pictures...
475
 */
476
class MWAWPictBitmapColor final : public MWAWPictBitmap
477
{
478
public:
479
  //! return the picture subtype
480
  SubType getSubType() const final
481
0
  {
482
0
    return Color;
483
0
  }
484
485
  /** a virtual function used to obtain a strict order,
486
  must be redefined in the subs class */
487
  int cmp(MWAWPict const &a) const final
488
0
  {
489
0
    int diff = MWAWPictBitmap::cmp(a);
490
0
    if (diff) return diff;
491
0
    auto const &aPict = static_cast<MWAWPictBitmapColor const &>(a);
492
493
0
    return m_data.cmp(aPict.m_data);
494
0
  }
495
496
  //! returns true if the picture is valid
497
  bool valid() const final
498
110k
  {
499
110k
    return m_data.ok();
500
110k
  }
501
  //! returns the average color
502
  MWAWColor getAverageColor() const final;
503
504
  //! the constructor
505
  explicit MWAWPictBitmapColor(MWAWVec2i const &sz, bool useAlphaChannel=false)
506
110k
    : MWAWPictBitmap(sz)
507
110k
    , m_data(sz)
508
110k
    , m_hasAlpha(useAlphaChannel)
509
110k
  {
510
110k
  }
511
512
  //! the picture size
513
  MWAWVec2i const &size() const
514
0
  {
515
0
    return m_data.size();
516
0
  }
517
  //! the number of rows
518
  int numRows() const
519
0
  {
520
0
    return m_data.numRows();
521
0
  }
522
  //! the number of columns
523
  int numColumns() const
524
0
  {
525
0
    return m_data.numColumns();
526
0
  }
527
  //! returns a cell content
528
  MWAWColor get(int i, int j) const
529
0
  {
530
0
    return m_data.get(i,j);
531
0
  }
532
  //! returns the cells content of a row
533
  MWAWColor const *getRow(int j) const
534
0
  {
535
0
    return m_data.getRow(j);
536
0
  }
537
538
  //! sets a cell contents
539
  void set(int i, int j, MWAWColor const &v)
540
67.9M
  {
541
67.9M
    m_data.set(i,j, v);
542
67.9M
  }
543
  //! sets all cell contents of a row
544
  void setRow(int j, MWAWColor const *val)
545
701k
  {
546
701k
    m_data.setRow(j, val);
547
701k
  }
548
  //! sets all cell contents of a column
549
  void setColumn(int i, MWAWColor const *val)
550
0
  {
551
0
    m_data.setColumn(i, val);
552
0
  }
553
554
protected:
555
  //! the function which creates the result file
556
  bool createFileData(librevenge::RVNGBinaryData &result) const final;
557
558
  //! the data
559
  MWAWPictBitmapContainer<MWAWColor> m_data;
560
561
  //! true if the bitmap has alpha color
562
  bool m_hasAlpha;
563
};
564
#endif
565
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: