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:
58 explicit MWAWPictBitmapContainer(MWAWVec2i const &sz) : m_size(sz), m_data(0L)
59 {
60 if (m_size[0]*m_size[1] == 0) return;
61 m_data = new T[size_t(m_size[0]*m_size[1])];
62 std::uninitialized_fill_n(m_data, m_size[0] * m_size[1], T());
63 }
66 {
67 if (m_data) delete [] m_data;
68 }
69
71 bool ok() const
72 {
73 return (m_data != 0L);
74 }
75
77 int cmp(MWAWPictBitmapContainer<T> const &orig) const
78 {
79 int diff = m_size.cmpY(orig.m_size);
80 if (diff) return diff;
81 if (!m_data) return orig.m_data ? 1 : 0;
82 if (!orig.m_data) return -1;
83 for (int i=0; i < m_size[0]*m_size[1]; i++) {
84 if (m_data[i] < orig.m_data[i]) return -1;
85 if (m_data[i] > orig.m_data[i]) return 1;
86 }
87 return 0;
88 }
90 MWAWVec2i const &size() const
91 {
92 return m_size;
93 }
95 int numRows() const
96 {
97 return m_size[0];
98 }
100 int numColumns() const
101 {
102 return m_size[1];
103 }
104
106 T const &get(int i, int j) const
107 {
108 if (m_data == 0L || i<0 || i >= m_size[0] || j<0 || j >= m_size[1])
110 return m_data[i+m_size[0]*j];
111 }
113 T const *getRow(int j) const
114 {
115 if (m_data == 0L || j<0 || j >= m_size[1])
117 return m_data+m_size[0]*j;
118 }
119
121 void set(int i, int j, T const &v)
122 {
123 if (m_data == 0L || i<0 || i >= m_size[0] || j<0 || j >= m_size[1]) {
124 MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::set: call with bad coordinate %d %d\n", i, j));
125 return;
126 }
127 m_data[i+j*m_size[0]] = v;
128 }
129
131 template <class U>
132 void setRow(int j, U const *val)
133 {
134 if (m_data == 0L || j<0 || j >= m_size[1]) {
135 MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::setRow: call with bad coordinate %d\n", j));
136 return;
137 }
138 for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
139 }
140
142 template <class U>
143 void setColumn(int i, U const *val)
144 {
145 if (m_data == 0L || i<0 || i >= m_size[0]) {
146 MWAW_DEBUG_MSG(("MWAWPictBitmapContainer::setColumn: call with bad coordinate %d\n", i));
147 return;
148 }
149 for (int j = 0, ind=i; j < m_size[1]; j++, ind+=m_size[0]) m_data[ind] = T(val[i]);
150 }
151
152private:
155protected:
160};
161
164{
165public:
171 int cmp(MWAWPictBitmapContainerBool const &orig) const
172 {
173 int diff = m_size.cmpY(orig.m_size);
174 if (diff) return diff;
175 if (!m_data) return orig.m_data ? 1 : 0;
176 if (!orig.m_data) return -1;
177 for (int i=0; i < m_size[0]*m_size[1]; i++) {
178 if (m_data[i] == orig.m_data[i]) continue;
179 return m_data[i] ? 1 : -1;
180 }
181 return 0;
182 }
183
185 void setRowPacked(int j, unsigned char const *val)
186 {
187 if (m_data == 0L || j<0 || j >= m_size[1]) {
188 MWAW_DEBUG_MSG(("MWAWPictBitmapContainerBool::setRowPacked: call with bad coordinate %d\n", j));
189 return;
190 }
191 for (int i = 0, ind = j*m_size[0]; i < m_size[0];) {
192 unsigned char v = *(val++);
193 unsigned char mask = 0x80;
194 for (int p = 0; p < 8 && i < m_size[0]; i++, p++, ind++) {
195 m_data[ind] = ((v&mask) != 0);
196 mask = static_cast<unsigned char>(mask >> 1);
197 }
198 }
199 }
200};
201
204{
205public:
207 virtual ~MWAWPictBitmap();
208
212 virtual Type getType() const
213 {
214 return MWAWPict::Bitmap;
215 }
217 virtual SubType getSubType() const = 0;
218
220 virtual bool getBinary(MWAWEmbeddedObject &picture) const
221 {
222 if (!valid()) return false;
223
224 librevenge::RVNGBinaryData data;
225 createFileData(data);
226 picture=MWAWEmbeddedObject(data, "image/pict");
227 return true;
228 }
229
231 virtual bool valid() const
232 {
233 return false;
234 }
235
238 virtual int cmp(MWAWPict const &a) const
239 {
240 int diff = MWAWPict::cmp(a);
241 if (diff) return diff;
242 MWAWPictBitmap const &aPict = static_cast<MWAWPictBitmap const &>(a);
243
244 // the type
245 diff = getSubType() - aPict.getSubType();
246 if (diff) return (diff < 0) ? -1 : 1;
247
248 return 0;
249 }
250
251protected:
253 virtual bool createFileData(librevenge::RVNGBinaryData &result) const = 0;
254
256 explicit MWAWPictBitmap(MWAWVec2i const &sz)
257 {
258 setBdBox(MWAWBox2f(MWAWVec2f(0,0), sz));
259 }
260};
261
264{
265public:
267 virtual SubType getSubType() const
268 {
269 return BW;
270 }
271
274 virtual int cmp(MWAWPict const &a) const
275 {
276 int diff = MWAWPictBitmap::cmp(a);
277 if (diff) return diff;
278 MWAWPictBitmapBW const &aPict = static_cast<MWAWPictBitmapBW const &>(a);
279
280 return m_data.cmp(aPict.m_data);
281 }
282
284 virtual bool valid() const
285 {
286 return m_data.ok();
287 }
288
290 explicit MWAWPictBitmapBW(MWAWVec2i const &sz) : MWAWPictBitmap(sz), m_data(sz) { }
291
293 MWAWVec2i const &size() const
294 {
295 return m_data.size();
296 }
298 int numRows() const
299 {
300 return m_data.numRows();
301 }
303 int numColumns() const
304 {
305 return m_data.numColumns();
306 }
308 bool get(int i, int j) const
309 {
310 return m_data.get(i,j);
311 }
313 bool const *getRow(int j) const
314 {
315 return m_data.getRow(j);
316 }
318 void set(int i, int j, bool v)
319 {
320 m_data.set(i,j, v);
321 }
323 void setRow(int j, bool const *val)
324 {
325 m_data.setRow(j, val);
326 }
328 void setRowPacked(int j, unsigned char const *val)
329 {
330 m_data.setRowPacked(j, val);
331 }
333 void setColumn(int i, bool const *val)
334 {
335 m_data.setColumn(i, val);
336 }
337
338protected:
340 virtual bool createFileData(librevenge::RVNGBinaryData &result) const;
341
344};
345
348{
349public:
351 virtual SubType getSubType() const
352 {
353 return Indexed;
354 }
355
358 virtual int cmp(MWAWPict const &a) const
359 {
360 int diff = MWAWPictBitmap::cmp(a);
361 if (diff) return diff;
362 MWAWPictBitmapIndexed const &aPict = static_cast<MWAWPictBitmapIndexed const &>(a);
363
364 diff=int(m_colors.size())-int(aPict.m_colors.size());
365 if (diff) return (diff < 0) ? -1 : 1;
366 for (size_t c=0; c < m_colors.size(); c++) {
367 if (m_colors[c] < aPict.m_colors[c])
368 return 1;
369 if (m_colors[c] > aPict.m_colors[c])
370 return -1;
371 }
372 return m_data.cmp(aPict.m_data);
373 }
374
376 virtual bool valid() const
377 {
378 return m_data.ok();
379 }
380
382 explicit MWAWPictBitmapIndexed(MWAWVec2i const &sz) : MWAWPictBitmap(sz), m_data(sz), m_colors() { }
383
385 MWAWVec2i const &size() const
386 {
387 return m_data.size();
388 }
390 int numRows() const
391 {
392 return m_data.numRows();
393 }
395 int numColumns() const
396 {
397 return m_data.numColumns();
398 }
400 int get(int i, int j) const
401 {
402 return m_data.get(i,j);
403 }
405 int const *getRow(int j) const
406 {
407 return m_data.getRow(j);
408 }
409
411 void set(int i, int j, int v)
412 {
413 m_data.set(i,j, v);
414 }
416 template <class U> void setRow(int j, U const *val)
417 {
418 m_data.setRow(j, val);
419 }
421 template <class U> void setColumn(int i, U const *val)
422 {
423 m_data.setColumn(i, val);
424 }
425
427 std::vector<MWAWColor> const &getColors() const
428 {
429 return m_colors;
430 }
432 void setColors(std::vector<MWAWColor> const &cols)
433 {
434 m_colors = cols;
435 }
436
437protected:
439 virtual bool createFileData(librevenge::RVNGBinaryData &result) const;
440
444 std::vector<MWAWColor> m_colors;
445};
446
455{
456public:
458 virtual SubType getSubType() const
459 {
460 return Indexed;
461 }
462
465 virtual int cmp(MWAWPict const &a) const
466 {
467 int diff = MWAWPictBitmap::cmp(a);
468 if (diff) return diff;
469 MWAWPictBitmapColor const &aPict = static_cast<MWAWPictBitmapColor const &>(a);
470
471 return m_data.cmp(aPict.m_data);
472 }
473
475 virtual bool valid() const
476 {
477 return m_data.ok();
478 }
479
481 MWAWPictBitmapColor(MWAWVec2i const &sz, bool useAlphaChannel=false) : MWAWPictBitmap(sz), m_data(sz), m_hasAlpha(useAlphaChannel) { }
482
484 MWAWVec2i const &size() const
485 {
486 return m_data.size();
487 }
489 int numRows() const
490 {
491 return m_data.numRows();
492 }
494 int numColumns() const
495 {
496 return m_data.numColumns();
497 }
499 MWAWColor get(int i, int j) const
500 {
501 return m_data.get(i,j);
502 }
504 MWAWColor const *getRow(int j) const
505 {
506 return m_data.getRow(j);
507 }
508
510 void set(int i, int j, MWAWColor const &v)
511 {
512 m_data.set(i,j, v);
513 }
515 void setRow(int j, MWAWColor const *val)
516 {
517 m_data.setRow(j, val);
518 }
520 void setColumn(int i, MWAWColor const *val)
521 {
522 m_data.setColumn(i, val);
523 }
524
525protected:
527 virtual bool createFileData(librevenge::RVNGBinaryData &result) const;
528
531
534};
535#endif
536// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
a bitmap of bool to store black-white bitmap
Definition: MWAWPictBitmap.hxx:264
void setColumn(int i, bool const *val)
sets all cell contents of a column
Definition: MWAWPictBitmap.hxx:333
void setRowPacked(int j, unsigned char const *val)
sets all cell contents of a row given packed m_data
Definition: MWAWPictBitmap.hxx:328
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictBitmap.hxx:267
void set(int i, int j, bool v)
sets a cell contents
Definition: MWAWPictBitmap.hxx:318
MWAWVec2i const & size() const
the picture size
Definition: MWAWPictBitmap.hxx:293
int numRows() const
the number of rows
Definition: MWAWPictBitmap.hxx:298
bool get(int i, int j) const
returns a cell content
Definition: MWAWPictBitmap.hxx:308
bool const * getRow(int j) const
returns the cells content of a row
Definition: MWAWPictBitmap.hxx:313
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:284
MWAWPictBitmapBW(MWAWVec2i const &sz)
the constructor
Definition: MWAWPictBitmap.hxx:290
virtual bool createFileData(librevenge::RVNGBinaryData &result) const
function which creates the result file
Definition: MWAWPictBitmap.cxx:235
int numColumns() const
the number of columns
Definition: MWAWPictBitmap.hxx:303
MWAWPictBitmapContainerBool m_data
the data
Definition: MWAWPictBitmap.hxx:343
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition: MWAWPictBitmap.hxx:274
void setRow(int j, bool const *val)
sets all cell contents of a row
Definition: MWAWPictBitmap.hxx:323
a bitmap of MWAWColor to store true color bitmap
Definition: MWAWPictBitmap.hxx:455
void set(int i, int j, MWAWColor const &v)
sets a cell contents
Definition: MWAWPictBitmap.hxx:510
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition: MWAWPictBitmap.hxx:465
bool m_hasAlpha
true if the bitmap has alpha color
Definition: MWAWPictBitmap.hxx:533
virtual SubType getSubType() const
return the picture subtype
Definition: MWAWPictBitmap.hxx:458
void setColumn(int i, MWAWColor const *val)
sets all cell contents of a column
Definition: MWAWPictBitmap.hxx:520
MWAWVec2i const & size() const
the picture size
Definition: MWAWPictBitmap.hxx:484
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:475
MWAWPictBitmapColor(MWAWVec2i const &sz, bool useAlphaChannel=false)
the constructor
Definition: MWAWPictBitmap.hxx:481
int numColumns() const
the number of columns
Definition: MWAWPictBitmap.hxx:494
MWAWPictBitmapContainer< MWAWColor > m_data
the data
Definition: MWAWPictBitmap.hxx:530
int numRows() const
the number of rows
Definition: MWAWPictBitmap.hxx:489
virtual bool createFileData(librevenge::RVNGBinaryData &result) const
the function which creates the result file
Definition: MWAWPictBitmap.cxx:244
void setRow(int j, MWAWColor const *val)
sets all cell contents of a row
Definition: MWAWPictBitmap.hxx:515
MWAWColor get(int i, int j) const
returns a cell content
Definition: MWAWPictBitmap.hxx:499
MWAWColor const * getRow(int j) const
returns the cells content of a row
Definition: MWAWPictBitmap.hxx:504
a bool container with a function to put packed row
Definition: MWAWPictBitmap.hxx:164
void setRowPacked(int j, unsigned char const *val)
allows to use packed m_data
Definition: MWAWPictBitmap.hxx:185
int cmp(MWAWPictBitmapContainerBool const &orig) const
a comparison operator
Definition: MWAWPictBitmap.hxx:171
~MWAWPictBitmapContainerBool()
destructor
Definition: MWAWPictBitmap.cxx:224
MWAWPictBitmapContainerBool(MWAWVec2i const &sz)
constructor
Definition: MWAWPictBitmap.hxx:167
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:159
void set(int i, int j, T const &v)
sets a cell m_data
Definition: MWAWPictBitmap.hxx:121
int numRows() const
gets the number of row
Definition: MWAWPictBitmap.hxx:95
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:143
MWAWVec2i m_size
the size
Definition: MWAWPictBitmap.hxx:157
void setRow(int j, U const *val)
sets a line of m_data
Definition: MWAWPictBitmap.hxx:132
MWAWPictBitmapContainer & operator=(MWAWPictBitmapContainer const &orig)
bool ok() const
returns ok, if the m_data is allocated
Definition: MWAWPictBitmap.hxx:71
virtual ~MWAWPictBitmapContainer()
destructor
Definition: MWAWPictBitmap.hxx:65
MWAWPictBitmapContainer(MWAWPictBitmapContainer const &orig)
T const * getRow(int j) const
accessor of a row m_data
Definition: MWAWPictBitmap.hxx:113
int cmp(MWAWPictBitmapContainer< T > const &orig) const
a comparison operator
Definition: MWAWPictBitmap.hxx:77
MWAWVec2i const & size() const
return the array size
Definition: MWAWPictBitmap.hxx:90
T const & get(int i, int j) const
accessor of a cell m_data
Definition: MWAWPictBitmap.hxx:106
int numColumns() const
gets the number of column
Definition: MWAWPictBitmap.hxx:100
a bitmap of int to store indexed bitmap
Definition: MWAWPictBitmap.hxx:348
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:376
MWAWPictBitmapIndexed(MWAWVec2i const &sz)
the constructor
Definition: MWAWPictBitmap.hxx:382
void setColumn(int i, U const *val)
sets all cell contents of a column
Definition: MWAWPictBitmap.hxx:421
virtual SubType getSubType() const
return the picture subtype
Definition: MWAWPictBitmap.hxx:351
MWAWVec2i const & size() const
the picture size
Definition: MWAWPictBitmap.hxx:385
void setColors(std::vector< MWAWColor > const &cols)
sets the array of indexed colors
Definition: MWAWPictBitmap.hxx:432
void setRow(int j, U const *val)
sets all cell contents of a row
Definition: MWAWPictBitmap.hxx:416
int get(int i, int j) const
returns a cell content
Definition: MWAWPictBitmap.hxx:400
std::vector< MWAWColor > m_colors
the colors
Definition: MWAWPictBitmap.hxx:444
std::vector< MWAWColor > const & getColors() const
returns the array of indexed colors
Definition: MWAWPictBitmap.hxx:427
int const * getRow(int j) const
returns the cells content of a row
Definition: MWAWPictBitmap.hxx:405
MWAWPictBitmapContainer< int > m_data
the m_data
Definition: MWAWPictBitmap.hxx:442
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition: MWAWPictBitmap.hxx:358
int numRows() const
the number of rows
Definition: MWAWPictBitmap.hxx:390
int numColumns() const
the number of columns
Definition: MWAWPictBitmap.hxx:395
virtual bool createFileData(librevenge::RVNGBinaryData &result) const
the function which creates the result file
Definition: MWAWPictBitmap.cxx:254
void set(int i, int j, int v)
sets a cell contents
Definition: MWAWPictBitmap.hxx:411
Generic class used to construct bitmap.
Definition: MWAWPictBitmap.hxx:204
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition: MWAWPictBitmap.hxx:238
virtual ~MWAWPictBitmap()
destructor
Definition: MWAWPictBitmap.cxx:228
SubType
the picture subtype: blackwhite, indexed, color
Definition: MWAWPictBitmap.hxx:210
@ BW
Definition: MWAWPictBitmap.hxx:210
@ Color
Definition: MWAWPictBitmap.hxx:210
@ Indexed
Definition: MWAWPictBitmap.hxx:210
MWAWPictBitmap(MWAWVec2i const &sz)
protected constructor: use check to construct a picture
Definition: MWAWPictBitmap.hxx:256
virtual SubType getSubType() const =0
returns the picture subtype
virtual bool createFileData(librevenge::RVNGBinaryData &result) const =0
abstract function which creates the result file
virtual bool getBinary(MWAWEmbeddedObject &picture) const
returns the final picture
Definition: MWAWPictBitmap.hxx:220
virtual Type getType() const
returns the picture type
Definition: MWAWPictBitmap.hxx:212
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:231
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:729
Definition: libmwaw_internal.hxx:146
MWAWBox2< float > MWAWBox2f
MWAWBox2 of float.
Definition: libmwaw_internal.hxx:1134
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition: libmwaw_internal.hxx:785
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:127
the class to store a color
Definition: libmwaw_internal.hxx:182
small class use to define a embedded object
Definition: libmwaw_internal.hxx:425

Generated on Wed Jan 19 2022 22:23:16 for libmwaw by doxygen 1.9.3