MWAWPictBitmap.hxx
Go to the documentation of this file.
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 <vector>
42
43#include "libmwaw_internal.hxx"
44#include "MWAWDebug.hxx"
45#include "MWAWPict.hxx"
46
48//
49// Some container
50//
52
54template <class T> class MWAWPictBitmapContainer
55{
56public:
59 : m_size(sz)
60 , m_data(nullptr)
61 {
62 if (m_size[0]*m_size[1] == 0) return;
63 m_data = new T[size_t(m_size[0]*m_size[1])];
64 std::uninitialized_fill_n(m_data, m_size[0] * m_size[1], T());
65 }
68 {
69 if (m_data) delete [] m_data;
70 }
71
73 bool ok() const
74 {
75 return (m_data != nullptr);
76 }
77
79 int cmp(MWAWPictBitmapContainer<T> const &orig) const
80 {
81 int diff = m_size.cmpY(orig.m_size);
82 if (diff) return diff;
83 if (!m_data) return orig.m_data ? 1 : 0;
84 if (!orig.m_data) return -1;
85 for (int i=0; i < m_size[0]*m_size[1]; i++) {
86 if (m_data[i] < orig.m_data[i]) return -1;
87 if (m_data[i] > orig.m_data[i]) return 1;
88 }
89 return 0;
90 }
92 MWAWVec2i const &size() const
93 {
94 return m_size;
95 }
97 int numRows() const
98 {
99 return m_size[0];
100 }
102 int numColumns() const
103 {
104 return m_size[1];
105 }
106
108 T const &get(int i, int j) const
109 {
110 if (m_data == nullptr || i<0 || i >= m_size[0] || j<0 || j >= m_size[1])
112 return m_data[i+m_size[0]*j];
113 }
115 T const *getRow(int j) const
116 {
117 if (m_data == nullptr || j<0 || j >= m_size[1])
119 return m_data+m_size[0]*j;
120 }
121
123 void set(int i, int j, T const &v)
124 {
125 if (m_data == nullptr || i<0 || i >= m_size[0] || j<0 || j >= m_size[1]) {
126 MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::set: call with bad coordinate %d %d\n", i, j));
127 return;
128 }
129 m_data[i+j*m_size[0]] = v;
130 }
131
133 template <class U>
134 void setRow(int j, U const *val)
135 {
136 if (m_data == nullptr || j<0 || j >= m_size[1]) {
137 MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::setRow: call with bad coordinate %d\n", j));
138 return;
139 }
140 for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
141 }
142
144 template <class U>
145 void setColumn(int i, U const *val)
146 {
147 if (m_data == nullptr || i<0 || i >= m_size[0]) {
148 MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::setColumn: call with bad coordinate %d\n", i));
149 return;
150 }
151 for (int j = 0, ind=i; j < m_size[1]; j++, ind+=m_size[0]) m_data[ind] = T(val[i]);
152 }
153
154private:
157protected:
162};
163
166{
167public:
170 : MWAWPictBitmapContainer<bool>(sz)
171 {
172 }
176 int cmp(MWAWPictBitmapContainerBool const &orig) const
177 {
178 int diff = m_size.cmpY(orig.m_size);
179 if (diff) return diff;
180 if (!m_data) return orig.m_data ? 1 : 0;
181 if (!orig.m_data) return -1;
182 for (int i=0; i < m_size[0]*m_size[1]; i++) {
183 if (m_data[i] == orig.m_data[i]) continue;
184 return m_data[i] ? 1 : -1;
185 }
186 return 0;
187 }
188
190 void setRowPacked(int j, unsigned char const *val, unsigned char const *end)
191 {
192 if (m_data == nullptr || j<0 || j >= m_size[1] || val >= end) {
193 MWAW_DEBUG_MSG(("MWAWPictBitmapContainerBool::setRowPacked: call with bad coordinate %d\n", j));
194 return;
195 }
196 for (int i = 0, ind = j*m_size[0]; i < m_size[0];) {
197 unsigned char v = (val < end) ? *(val++) : 0;
198 unsigned char mask = 0x80;
199 for (int p = 0; p < 8 && i < m_size[0]; i++, p++, ind++) {
200 m_data[ind] = ((v&mask) != 0);
201 mask = static_cast<unsigned char>(mask >> 1);
202 }
203 }
204 }
205};
206
209{
210public:
212 ~MWAWPictBitmap() override;
213
217 Type getType() const override
218 {
219 return MWAWPict::Bitmap;
220 }
222 virtual SubType getSubType() const = 0;
223
225 bool getBinary(MWAWEmbeddedObject &picture) const override
226 {
227 if (!valid()) return false;
228
229 librevenge::RVNGBinaryData data;
230 createFileData(data);
231 picture=MWAWEmbeddedObject(data, "image/pict");
232 return true;
233 }
234
236 virtual bool valid() const
237 {
238 return false;
239 }
240
243 int cmp(MWAWPict const &a) const override
244 {
245 int diff = MWAWPict::cmp(a);
246 if (diff) return diff;
247 auto const &aPict = static_cast<MWAWPictBitmap const &>(a);
248
249 // the type
250 diff = getSubType() - aPict.getSubType();
251 if (diff) return (diff < 0) ? -1 : 1;
252
253 return 0;
254 }
255
256protected:
258 virtual bool createFileData(librevenge::RVNGBinaryData &result) const = 0;
259
261 explicit MWAWPictBitmap(MWAWVec2i const &sz)
262 {
264 }
265};
266
269{
270public:
272 SubType getSubType() const final
273 {
274 return BW;
275 }
276
279 int cmp(MWAWPict const &a) const final
280 {
281 int diff = MWAWPictBitmap::cmp(a);
282 if (diff) return diff;
283 auto const &aPict = static_cast<MWAWPictBitmapBW const &>(a);
284
285 return m_data.cmp(aPict.m_data);
286 }
287
289 bool valid() const final
290 {
291 return m_data.ok();
292 }
293
295 explicit MWAWPictBitmapBW(MWAWVec2i const &sz)
296 : MWAWPictBitmap(sz)
297 , m_data(sz)
298 {
299 }
300
302 MWAWVec2i const &size() const
303 {
304 return m_data.size();
305 }
307 int numRows() const
308 {
309 return m_data.numRows();
310 }
312 int numColumns() const
313 {
314 return m_data.numColumns();
315 }
317 bool get(int i, int j) const
318 {
319 return m_data.get(i,j);
320 }
322 bool const *getRow(int j) const
323 {
324 return m_data.getRow(j);
325 }
327 void set(int i, int j, bool v)
328 {
329 m_data.set(i,j, v);
330 }
332 void setRow(int j, bool const *val)
333 {
334 m_data.setRow(j, val);
335 }
337 void setRowPacked(int j, unsigned char const *val, unsigned char const *end)
338 {
339 m_data.setRowPacked(j, val, end);
340 }
342 void setColumn(int i, bool const *val)
343 {
344 m_data.setColumn(i, val);
345 }
346
347protected:
349 bool createFileData(librevenge::RVNGBinaryData &result) const final;
350
353};
354
357{
358public:
360 SubType getSubType() const final
361 {
362 return Indexed;
363 }
364
367 int cmp(MWAWPict const &a) const final
368 {
369 int diff = MWAWPictBitmap::cmp(a);
370 if (diff) return diff;
371 auto const &aPict = static_cast<MWAWPictBitmapIndexed const &>(a);
372
373 diff=int(m_colors.size())-int(aPict.m_colors.size());
374 if (diff) return (diff < 0) ? -1 : 1;
375 for (size_t c=0; c < m_colors.size(); c++) {
376 if (m_colors[c] < aPict.m_colors[c])
377 return 1;
378 if (m_colors[c] > aPict.m_colors[c])
379 return -1;
380 }
381 return m_data.cmp(aPict.m_data);
382 }
383
385 bool valid() const final
386 {
387 return m_data.ok();
388 }
389
392 : MWAWPictBitmap(sz)
393 , m_data(sz)
394 , m_colors()
395 {
396 }
397
399 MWAWVec2i const &size() const
400 {
401 return m_data.size();
402 }
404 int numRows() const
405 {
406 return m_data.numRows();
407 }
409 int numColumns() const
410 {
411 return m_data.numColumns();
412 }
414 int get(int i, int j) const
415 {
416 return m_data.get(i,j);
417 }
419 int const *getRow(int j) const
420 {
421 return m_data.getRow(j);
422 }
423
425 void set(int i, int j, int v)
426 {
427 m_data.set(i,j, v);
428 }
430 template <class U> void setRow(int j, U const *val)
431 {
432 m_data.setRow(j, val);
433 }
435 template <class U> void setColumn(int i, U const *val)
436 {
437 m_data.setColumn(i, val);
438 }
439
441 std::vector<MWAWColor> const &getColors() const
442 {
443 return m_colors;
444 }
446 void setColors(std::vector<MWAWColor> const &cols)
447 {
448 m_colors = cols;
449 }
450
451protected:
453 bool createFileData(librevenge::RVNGBinaryData &result) const final;
454
458 std::vector<MWAWColor> m_colors;
459};
460
469{
470public:
472 SubType getSubType() const final
473 {
474 return Color;
475 }
476
479 int cmp(MWAWPict const &a) const final
480 {
481 int diff = MWAWPictBitmap::cmp(a);
482 if (diff) return diff;
483 auto const &aPict = static_cast<MWAWPictBitmapColor const &>(a);
484
485 return m_data.cmp(aPict.m_data);
486 }
487
489 bool valid() const final
490 {
491 return m_data.ok();
492 }
493
495 MWAWPictBitmapColor(MWAWVec2i const &sz, bool useAlphaChannel=false)
496 : MWAWPictBitmap(sz)
497 , m_data(sz)
498 , m_hasAlpha(useAlphaChannel)
499 {
500 }
501
503 MWAWVec2i const &size() const
504 {
505 return m_data.size();
506 }
508 int numRows() const
509 {
510 return m_data.numRows();
511 }
513 int numColumns() const
514 {
515 return m_data.numColumns();
516 }
518 MWAWColor get(int i, int j) const
519 {
520 return m_data.get(i,j);
521 }
523 MWAWColor const *getRow(int j) const
524 {
525 return m_data.getRow(j);
526 }
527
529 void set(int i, int j, MWAWColor const &v)
530 {
531 m_data.set(i,j, v);
532 }
534 void setRow(int j, MWAWColor const *val)
535 {
536 m_data.setRow(j, val);
537 }
539 void setColumn(int i, MWAWColor const *val)
540 {
541 m_data.setColumn(i, val);
542 }
543
544protected:
546 bool createFileData(librevenge::RVNGBinaryData &result) const final;
547
550
553};
554#endif
555// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
a bitmap of bool to store black-white bitmap
Definition MWAWPictBitmap.hxx:269
void setColumn(int i, bool const *val)
sets all cell contents of a column
Definition MWAWPictBitmap.hxx:342
void setRowPacked(int j, unsigned char const *val, unsigned char const *end)
sets all cell contents of a row given packed m_data
Definition MWAWPictBitmap.hxx:337
void set(int i, int j, bool v)
sets a cell contents
Definition MWAWPictBitmap.hxx:327
MWAWVec2i const & size() const
the picture size
Definition MWAWPictBitmap.hxx:302
int numRows() const
the number of rows
Definition MWAWPictBitmap.hxx:307
bool get(int i, int j) const
returns a cell content
Definition MWAWPictBitmap.hxx:317
bool const * getRow(int j) const
returns the cells content of a row
Definition MWAWPictBitmap.hxx:322
SubType getSubType() const final
returns the picture subtype
Definition MWAWPictBitmap.hxx:272
MWAWPictBitmapBW(MWAWVec2i const &sz)
the constructor
Definition MWAWPictBitmap.hxx:295
int cmp(MWAWPict const &a) const final
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition MWAWPictBitmap.hxx:279
int numColumns() const
the number of columns
Definition MWAWPictBitmap.hxx:312
bool createFileData(librevenge::RVNGBinaryData &result) const final
function which creates the result file
Definition MWAWPictBitmap.cxx:503
MWAWPictBitmapContainerBool m_data
the data
Definition MWAWPictBitmap.hxx:352
void setRow(int j, bool const *val)
sets all cell contents of a row
Definition MWAWPictBitmap.hxx:332
bool valid() const final
returns true if the picture is valid
Definition MWAWPictBitmap.hxx:289
a bitmap of MWAWColor to store true color bitmap
Definition MWAWPictBitmap.hxx:469
SubType getSubType() const final
return the picture subtype
Definition MWAWPictBitmap.hxx:472
void set(int i, int j, MWAWColor const &v)
sets a cell contents
Definition MWAWPictBitmap.hxx:529
bool m_hasAlpha
true if the bitmap has alpha color
Definition MWAWPictBitmap.hxx:552
bool createFileData(librevenge::RVNGBinaryData &result) const final
the function which creates the result file
Definition MWAWPictBitmap.cxx:516
int cmp(MWAWPict const &a) const final
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition MWAWPictBitmap.hxx:479
void setColumn(int i, MWAWColor const *val)
sets all cell contents of a column
Definition MWAWPictBitmap.hxx:539
MWAWVec2i const & size() const
the picture size
Definition MWAWPictBitmap.hxx:503
bool valid() const final
returns true if the picture is valid
Definition MWAWPictBitmap.hxx:489
MWAWPictBitmapColor(MWAWVec2i const &sz, bool useAlphaChannel=false)
the constructor
Definition MWAWPictBitmap.hxx:495
int numColumns() const
the number of columns
Definition MWAWPictBitmap.hxx:513
MWAWPictBitmapContainer< MWAWColor > m_data
the data
Definition MWAWPictBitmap.hxx:549
int numRows() const
the number of rows
Definition MWAWPictBitmap.hxx:508
void setRow(int j, MWAWColor const *val)
sets all cell contents of a row
Definition MWAWPictBitmap.hxx:534
MWAWColor get(int i, int j) const
returns a cell content
Definition MWAWPictBitmap.hxx:518
MWAWColor const * getRow(int j) const
returns the cells content of a row
Definition MWAWPictBitmap.hxx:523
a bool container with a function to put packed row
Definition MWAWPictBitmap.hxx:166
~MWAWPictBitmapContainerBool() final
destructor
Definition MWAWPictBitmap.cxx:492
int cmp(MWAWPictBitmapContainerBool const &orig) const
a comparison operator
Definition MWAWPictBitmap.hxx:176
MWAWPictBitmapContainerBool(MWAWVec2i const &sz)
constructor
Definition MWAWPictBitmap.hxx:169
void setRowPacked(int j, unsigned char const *val, unsigned char const *end)
allows to use packed m_data
Definition MWAWPictBitmap.hxx:190
a template class to store a 2D array of m_data
Definition MWAWPictBitmap.hxx:55
T * m_data
the m_data placed by row ie. d_00, d_10, ... , d_{X-1}0, ..
Definition MWAWPictBitmap.hxx:161
MWAWPictBitmapContainer(MWAWPictBitmapContainer const &orig)=delete
void set(int i, int j, T const &v)
sets a cell m_data
Definition MWAWPictBitmap.hxx:123
int numRows() const
gets the number of row
Definition MWAWPictBitmap.hxx:97
MWAWPictBitmapContainer(MWAWVec2i const &sz)
constructor given size
Definition MWAWPictBitmap.hxx:58
void setColumn(int i, U const *val)
sets a column of m_data
Definition MWAWPictBitmap.hxx:145
MWAWVec2i m_size
the size
Definition MWAWPictBitmap.hxx:159
void setRow(int j, U const *val)
sets a line of m_data
Definition MWAWPictBitmap.hxx:134
MWAWPictBitmapContainer & operator=(MWAWPictBitmapContainer const &orig)=delete
bool ok() const
returns ok, if the m_data is allocated
Definition MWAWPictBitmap.hxx:73
virtual ~MWAWPictBitmapContainer()
destructor
Definition MWAWPictBitmap.hxx:67
T const * getRow(int j) const
accessor of a row m_data
Definition MWAWPictBitmap.hxx:115
int cmp(MWAWPictBitmapContainer< T > const &orig) const
a comparison operator
Definition MWAWPictBitmap.hxx:79
MWAWVec2i const & size() const
return the array size
Definition MWAWPictBitmap.hxx:92
T const & get(int i, int j) const
accessor of a cell m_data
Definition MWAWPictBitmap.hxx:108
int numColumns() const
gets the number of column
Definition MWAWPictBitmap.hxx:102
a bitmap of int to store indexed bitmap
Definition MWAWPictBitmap.hxx:357
MWAWPictBitmapIndexed(MWAWVec2i const &sz)
the constructor
Definition MWAWPictBitmap.hxx:391
void setColumn(int i, U const *val)
sets all cell contents of a column
Definition MWAWPictBitmap.hxx:435
MWAWVec2i const & size() const
the picture size
Definition MWAWPictBitmap.hxx:399
void setColors(std::vector< MWAWColor > const &cols)
sets the array of indexed colors
Definition MWAWPictBitmap.hxx:446
void setRow(int j, U const *val)
sets all cell contents of a row
Definition MWAWPictBitmap.hxx:430
int get(int i, int j) const
returns a cell content
Definition MWAWPictBitmap.hxx:414
std::vector< MWAWColor > m_colors
the colors
Definition MWAWPictBitmap.hxx:458
std::vector< MWAWColor > const & getColors() const
returns the array of indexed colors
Definition MWAWPictBitmap.hxx:441
int const * getRow(int j) const
returns the cells content of a row
Definition MWAWPictBitmap.hxx:419
SubType getSubType() const final
return the picture subtype
Definition MWAWPictBitmap.hxx:360
MWAWPictBitmapContainer< int > m_data
the m_data
Definition MWAWPictBitmap.hxx:456
int numRows() const
the number of rows
Definition MWAWPictBitmap.hxx:404
int cmp(MWAWPict const &a) const final
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition MWAWPictBitmap.hxx:367
bool valid() const final
returns true if the picture is valid
Definition MWAWPictBitmap.hxx:385
int numColumns() const
the number of columns
Definition MWAWPictBitmap.hxx:409
void set(int i, int j, int v)
sets a cell contents
Definition MWAWPictBitmap.hxx:425
bool createFileData(librevenge::RVNGBinaryData &result) const final
the function which creates the result file
Definition MWAWPictBitmap.cxx:530
Generic class used to construct bitmap.
Definition MWAWPictBitmap.hxx:209
SubType
the picture subtype: blackwhite, indexed, color
Definition MWAWPictBitmap.hxx:215
@ BW
Definition MWAWPictBitmap.hxx:215
@ Color
Definition MWAWPictBitmap.hxx:215
@ Indexed
Definition MWAWPictBitmap.hxx:215
MWAWPictBitmap(MWAWVec2i const &sz)
protected constructor: use check to construct a picture
Definition MWAWPictBitmap.hxx:261
virtual SubType getSubType() const =0
returns the picture subtype
Type getType() const override
returns the picture type
Definition MWAWPictBitmap.hxx:217
virtual bool createFileData(librevenge::RVNGBinaryData &result) const =0
abstract function which creates the result file
~MWAWPictBitmap() override
destructor
Definition MWAWPictBitmap.cxx:496
int cmp(MWAWPict const &a) const override
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition MWAWPictBitmap.hxx:243
bool getBinary(MWAWEmbeddedObject &picture) const override
returns the final picture
Definition MWAWPictBitmap.hxx:225
virtual bool valid() const
returns true if the picture is valid
Definition MWAWPictBitmap.hxx:236
Generic function used to define/store a picture.
Definition MWAWPict.hxx:52
Type
the different picture types:
Definition MWAWPict.hxx:63
@ Bitmap
Definition MWAWPict.hxx:63
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition MWAWPict.hxx:101
void setBdBox(MWAWBox2f const &box)
sets the bdbox of the picture
Definition MWAWPict.hxx:84
int cmpY(MWAWVec2< T > const &p) const
a comparison function: which first compares y then x
Definition libmwaw_internal.hxx:786
Definition libmwaw_internal.hxx:148
MWAWBox2< float > MWAWBox2f
MWAWBox2 of float.
Definition libmwaw_internal.hxx:1193
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition libmwaw_internal.hxx:842
#define MWAW_DEBUG_MSG(M)
Definition libmwaw_internal.hxx:129
the class to store a color
Definition libmwaw_internal.hxx:192
small class use to define a embedded object
Definition libmwaw_internal.hxx:467

Generated on Sat Jul 20 2024 15:45:35 for libmwaw by doxygen 1.9.8