Coverage Report

Created: 2026-10-28 06:34

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
868k
    : m_size(sz)
61
868k
    , m_data(nullptr)
62
868k
  {
63
868k
    if (m_size[0]<=0 || m_size[1]<=0 || m_size[0]>(std::numeric_limits<int>::max)()/m_size[1]) return;
64
866k
    size_t const numElements=size_t(m_size[0])*size_t(m_size[1]);
65
866k
    m_data = new T[numElements];
66
866k
    std::uninitialized_fill_n(m_data, numElements, T());
67
866k
  }
MWAWPictBitmapContainer<int>::MWAWPictBitmapContainer(MWAWVec2<int> const&)
Line
Count
Source
60
840k
    : m_size(sz)
61
840k
    , m_data(nullptr)
62
840k
  {
63
840k
    if (m_size[0]<=0 || m_size[1]<=0 || m_size[0]>(std::numeric_limits<int>::max)()/m_size[1]) return;
64
840k
    size_t const numElements=size_t(m_size[0])*size_t(m_size[1]);
65
840k
    m_data = new T[numElements];
66
840k
    std::uninitialized_fill_n(m_data, numElements, T());
67
840k
  }
MWAWPictBitmapContainer<bool>::MWAWPictBitmapContainer(MWAWVec2<int> const&)
Line
Count
Source
60
5.95k
    : m_size(sz)
61
5.95k
    , m_data(nullptr)
62
5.95k
  {
63
5.95k
    if (m_size[0]<=0 || m_size[1]<=0 || m_size[0]>(std::numeric_limits<int>::max)()/m_size[1]) return;
64
5.60k
    size_t const numElements=size_t(m_size[0])*size_t(m_size[1]);
65
5.60k
    m_data = new T[numElements];
66
5.60k
    std::uninitialized_fill_n(m_data, numElements, T());
67
5.60k
  }
MWAWPictBitmapContainer<MWAWColor>::MWAWPictBitmapContainer(MWAWVec2<int> const&)
Line
Count
Source
60
22.3k
    : m_size(sz)
61
22.3k
    , m_data(nullptr)
62
22.3k
  {
63
22.3k
    if (m_size[0]<=0 || m_size[1]<=0 || m_size[0]>(std::numeric_limits<int>::max)()/m_size[1]) return;
64
20.8k
    size_t const numElements=size_t(m_size[0])*size_t(m_size[1]);
65
20.8k
    m_data = new T[numElements];
66
20.8k
    std::uninitialized_fill_n(m_data, numElements, T());
67
20.8k
  }
68
  //! destructor
69
  virtual ~MWAWPictBitmapContainer()
70
868k
  {
71
868k
    if (m_data) delete [] m_data;
72
868k
  }
MWAWPictBitmapContainer<int>::~MWAWPictBitmapContainer()
Line
Count
Source
70
840k
  {
71
840k
    if (m_data) delete [] m_data;
72
840k
  }
MWAWPictBitmapContainer<bool>::~MWAWPictBitmapContainer()
Line
Count
Source
70
5.95k
  {
71
5.95k
    if (m_data) delete [] m_data;
72
5.95k
  }
MWAWPictBitmapContainer<MWAWColor>::~MWAWPictBitmapContainer()
Line
Count
Source
70
22.3k
  {
71
22.3k
    if (m_data) delete [] m_data;
72
22.3k
  }
73
74
  //! returns ok, if the m_data is allocated
75
  bool ok() const
76
876k
  {
77
876k
    return (m_data != nullptr);
78
876k
  }
MWAWPictBitmapContainer<bool>::ok() const
Line
Count
Source
76
10.2k
  {
77
10.2k
    return (m_data != nullptr);
78
10.2k
  }
MWAWPictBitmapContainer<int>::ok() const
Line
Count
Source
76
841k
  {
77
841k
    return (m_data != nullptr);
78
841k
  }
MWAWPictBitmapContainer<MWAWColor>::ok() const
Line
Count
Source
76
24.2k
  {
77
24.2k
    return (m_data != nullptr);
78
24.2k
  }
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
864k
  {
96
864k
    return m_size;
97
864k
  }
MWAWPictBitmapContainer<bool>::size() const
Line
Count
Source
95
5.51k
  {
96
5.51k
    return m_size;
97
5.51k
  }
MWAWPictBitmapContainer<int>::size() const
Line
Count
Source
95
838k
  {
96
838k
    return m_size;
97
838k
  }
MWAWPictBitmapContainer<MWAWColor>::size() const
Line
Count
Source
95
20.4k
  {
96
20.4k
    return m_size;
97
20.4k
  }
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
9.71M
  {
119
9.71M
    if (m_data == nullptr || j<0 || j >= m_size[1])
120
0
      throw libmwaw::GenericException();
121
9.71M
    return m_data+m_size[0]*j;
122
9.71M
  }
MWAWPictBitmapContainer<bool>::getRow(int) const
Line
Count
Source
118
2.04M
  {
119
2.04M
    if (m_data == nullptr || j<0 || j >= m_size[1])
120
0
      throw libmwaw::GenericException();
121
2.04M
    return m_data+m_size[0]*j;
122
2.04M
  }
MWAWPictBitmapContainer<int>::getRow(int) const
Line
Count
Source
118
6.84M
  {
119
6.84M
    if (m_data == nullptr || j<0 || j >= m_size[1])
120
0
      throw libmwaw::GenericException();
121
6.84M
    return m_data+m_size[0]*j;
122
6.84M
  }
MWAWPictBitmapContainer<MWAWColor>::getRow(int) const
Line
Count
Source
118
833k
  {
119
833k
    if (m_data == nullptr || j<0 || j >= m_size[1])
120
0
      throw libmwaw::GenericException();
121
833k
    return m_data+m_size[0]*j;
122
833k
  }
123
124
  //! sets a cell m_data
125
  void set(int i, int j, T const &v)
126
177M
  {
127
177M
    if (m_data == nullptr || i<0 || i >= m_size[0] || j<0 || j >= m_size[1]) {
128
142k
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::set: call with bad coordinate %d %d\n", i, j));
129
142k
      return;
130
142k
    }
131
176M
    m_data[i+j*m_size[0]] = v;
132
176M
  }
MWAWPictBitmapContainer<int>::set(int, int, int const&)
Line
Count
Source
126
88.8M
  {
127
88.8M
    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
88.8M
    m_data[i+j*m_size[0]] = v;
132
88.8M
  }
MWAWPictBitmapContainer<bool>::set(int, int, bool const&)
Line
Count
Source
126
6.75M
  {
127
6.75M
    if (m_data == nullptr || i<0 || i >= m_size[0] || j<0 || j >= m_size[1]) {
128
142k
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::set: call with bad coordinate %d %d\n", i, j));
129
142k
      return;
130
142k
    }
131
6.61M
    m_data[i+j*m_size[0]] = v;
132
6.61M
  }
MWAWPictBitmapContainer<MWAWColor>::set(int, int, MWAWColor const&)
Line
Count
Source
126
81.4M
  {
127
81.4M
    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
81.4M
    m_data[i+j*m_size[0]] = v;
132
81.4M
  }
133
134
  //! sets a line of m_data
135
  template <class U>
136
  void setRow(int j, U const *val)
137
7.36M
  {
138
7.36M
    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
633M
    for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
143
7.36M
  }
Unexecuted instantiation: void MWAWPictBitmapContainer<bool>::setRow<bool>(int, bool const*)
void MWAWPictBitmapContainer<MWAWColor>::setRow<MWAWColor>(int, MWAWColor const*)
Line
Count
Source
137
691k
  {
138
691k
    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
573M
    for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
143
691k
  }
void MWAWPictBitmapContainer<int>::setRow<int>(int, int const*)
Line
Count
Source
137
6.67M
  {
138
6.67M
    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
60.0M
    for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
143
6.67M
  }
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
5.95k
    : MWAWPictBitmapContainer<bool>(sz)
173
5.95k
  {
174
5.95k
  }
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.96M
  {
194
1.96M
    if (m_data == nullptr || j<0 || j >= m_size[1] || val >= end) {
195
17.3k
      MWAW_DEBUG_MSG(("MWAWPictBitmapContainerBool::setRowPacked: call with bad coordinate %d\n", j));
196
17.3k
      return;
197
17.3k
    }
198
5.98M
    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
30.1M
      for (int p = 0; p < 8 && i < m_size[0]; i++, p++, ind++) {
202
26.0M
        m_data[ind] = ((v&mask) != 0);
203
26.0M
        mask = static_cast<unsigned char>(mask >> 1);
204
26.0M
      }
205
4.04M
    }
206
1.94M
  }
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
866k
  {
229
866k
    if (!valid()) return false;
230
231
864k
    librevenge::RVNGBinaryData data;
232
864k
    createFileData(data);
233
864k
    picture=MWAWEmbeddedObject(data, "image/pict");
234
864k
    return true;
235
866k
  }
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
868k
  {
267
868k
    setBdBox(MWAWBox2f(MWAWVec2f(0,0), MWAWVec2f(sz)));
268
868k
  }
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
10.2k
  {
295
10.2k
    return m_data.ok();
296
10.2k
  }
297
298
  //! the constructor
299
  explicit MWAWPictBitmapBW(MWAWVec2i const &sz)
300
5.95k
    : MWAWPictBitmap(sz)
301
5.95k
    , m_data(sz)
302
5.95k
  {
303
5.95k
  }
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
6.75M
  {
333
6.75M
    m_data.set(i,j, v);
334
6.75M
  }
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.96M
  {
343
1.96M
    m_data.setRowPacked(j, val, end);
344
1.96M
  }
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
841k
  {
393
841k
    return m_data.ok();
394
841k
  }
395
  //! returns the average color
396
  MWAWColor getAverageColor() const final;
397
398
  //! the constructor
399
  explicit MWAWPictBitmapIndexed(MWAWVec2i const &sz)
400
840k
    : MWAWPictBitmap(sz)
401
840k
    , m_data(sz)
402
840k
    , m_colors()
403
840k
  {
404
840k
  }
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
88.8M
  {
435
88.8M
    m_data.set(i,j, v);
436
88.8M
  }
437
  //! sets all cell contents of a row
438
  template <class U> void setRow(int j, U const *val)
439
6.67M
  {
440
6.67M
    m_data.setRow(j, val);
441
6.67M
  }
void MWAWPictBitmapIndexed::setRow<int>(int, int const*)
Line
Count
Source
439
6.67M
  {
440
6.67M
    m_data.setRow(j, val);
441
6.67M
  }
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
840k
  {
456
840k
    m_colors = cols;
457
840k
  }
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
24.2k
  {
499
24.2k
    return m_data.ok();
500
24.2k
  }
501
  //! returns the average color
502
  MWAWColor getAverageColor() const final;
503
504
  //! the constructor
505
  explicit MWAWPictBitmapColor(MWAWVec2i const &sz, bool useAlphaChannel=false)
506
22.3k
    : MWAWPictBitmap(sz)
507
22.3k
    , m_data(sz)
508
22.3k
    , m_hasAlpha(useAlphaChannel)
509
22.3k
  {
510
22.3k
  }
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
81.4M
  {
541
81.4M
    m_data.set(i,j, v);
542
81.4M
  }
543
  //! sets all cell contents of a row
544
  void setRow(int j, MWAWColor const *val)
545
691k
  {
546
691k
    m_data.setRow(j, val);
547
691k
  }
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: