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 #include <assert.h>
41 
42 #include <vector>
43 
44 #include "libmwaw_internal.hxx"
45 #include "MWAWPict.hxx"
46 
48 //
49 // Some container
50 //
52 
54 template <class T> class MWAWPictBitmapContainer
55 {
56 public:
59  {
60  if (m_size[0]*m_size[1] != 0) m_data = new T[size_t(m_size[0]*m_size[1])];
61  }
64  {
65  if (m_data) delete [] m_data;
66  }
67 
69  bool ok() const
70  {
71  return (m_data != 0L);
72  }
73 
75  int cmp(MWAWPictBitmapContainer<T> const &orig) const
76  {
77  int diff = m_size.cmpY(orig.m_size);
78  if (diff) return diff;
79  if (!m_data) return orig.m_data ? 1 : 0;
80  if (!orig.m_data) return -1;
81  for (int i=0; i < m_size[0]*m_size[1]; i++) {
82  if (m_data[i] < orig.m_data[i]) return -1;
83  if (m_data[i] > orig.m_data[i]) return 1;
84  }
85  return 0;
86  }
88  Vec2i const &size() const
89  {
90  return m_size;
91  }
93  int numRows() const
94  {
95  return m_size[0];
96  }
98  int numColumns() const
99  {
100  return m_size[1];
101  }
102 
104  T const &get(int i, int j) const
105  {
106  assert(m_data != 0L && i>=0 && i < m_size[0] && j>=0 && j < m_size[1]);
107  return m_data[i+m_size[0]*j];
108  }
110  T const *getRow(int j) const
111  {
112  assert(m_data != 0L && j>=0 && j < m_size[1]);
113  return m_data+m_size[0]*j;
114  }
115 
117  void set(int i, int j, T const &v)
118  {
119  assert(m_data != 0L && i>=0 && i < m_size[0] && j>=0 && j < m_size[1]);
120  m_data[i+j*m_size[0]] = v;
121  }
122 
124  template <class U>
125  void setRow(int j, U const *val)
126  {
127  assert(m_data != 0L && j>=0 && j < m_size[1]);
128  for (int i = 0, ind=j*m_size[0]; i < m_size[0]; i++, ind++) m_data[ind] = T(val[i]);
129  }
130 
132  template <class U>
133  void setColumn(int i, U const *val)
134  {
135  assert(m_data != 0L && i>=0 && i < m_size[0]);
136  for (int j = 0, ind=i; j < m_size[1]; j++, ind+=m_size[0]) m_data[ind] = T(val[i]);
137  }
138 
139 private:
142 protected:
146  T *m_data;
147 };
148 
151 {
152 public:
155 
157  int cmp(MWAWPictBitmapContainerBool const &orig) const
158  {
159  int diff = m_size.cmpY(orig.m_size);
160  if (diff) return diff;
161  if (!m_data) return orig.m_data ? 1 : 0;
162  if (!orig.m_data) return -1;
163  for (int i=0; i < m_size[0]*m_size[1]; i++) {
164  if (m_data[i] == orig.m_data[i]) continue;
165  return m_data[i] ? 1 : -1;
166  }
167  return 0;
168  }
169 
171  void setRowPacked(int j, unsigned char const *val)
172  {
173  assert(m_data != 0L && j>=0 && j < m_size[1]);
174  for (int i = 0, ind = j*m_size[0]; i < m_size[0];) {
175  unsigned char v = *(val++);
176  unsigned char mask = 0x80;
177  for (int p = 0; p < 8 && i < m_size[0]; i++, p++, ind++) {
178  m_data[ind] = ((v&mask) != 0);
179  mask = (unsigned char)(mask >> 1);
180  }
181  }
182  }
183 };
184 
186 class MWAWPictBitmap : public MWAWPict
187 {
188 public:
190  enum SubType { BW, Indexed, Color };
192  virtual Type getType() const
193  {
194  return MWAWPict::Bitmap;
195  }
197  virtual SubType getSubType() const = 0;
198 
200  virtual bool getBinary(librevenge::RVNGBinaryData &res, std::string &s) const
201  {
202  if (!valid()) return false;
203 
204  s = "image/pict";
205  createFileData(res);
206  return true;
207  }
208 
210  virtual bool valid() const
211  {
212  return false;
213  }
214 
217  virtual int cmp(MWAWPict const &a) const
218  {
219  int diff = MWAWPict::cmp(a);
220  if (diff) return diff;
221  MWAWPictBitmap const &aPict = static_cast<MWAWPictBitmap const &>(a);
222 
223  // the type
224  diff = getSubType() - aPict.getSubType();
225  if (diff) return (diff < 0) ? -1 : 1;
226 
227  return 0;
228  }
229 
230 protected:
232  virtual bool createFileData(librevenge::RVNGBinaryData &result) const = 0;
233 
236  {
237  setBdBox(Box2f(Vec2f(0,0), sz));
238  }
239 };
240 
243 {
244 public:
246  virtual SubType getSubType() const
247  {
248  return BW;
249  }
250 
253  virtual int cmp(MWAWPict const &a) const
254  {
255  int diff = MWAWPictBitmap::cmp(a);
256  if (diff) return diff;
257  MWAWPictBitmapBW const &aPict = static_cast<MWAWPictBitmapBW const &>(a);
258 
259  return m_data.cmp(aPict.m_data);
260  }
261 
263  virtual bool valid() const
264  {
265  return m_data.ok();
266  }
267 
269  MWAWPictBitmapBW(Vec2i const &sz) : MWAWPictBitmap(sz), m_data(sz) { }
270 
272  Vec2i const &size() const
273  {
274  return m_data.size();
275  }
277  int numRows() const
278  {
279  return m_data.numRows();
280  }
282  int numColumns() const
283  {
284  return m_data.numColumns();
285  }
287  bool get(int i, int j) const
288  {
289  return m_data.get(i,j);
290  }
292  bool const *getRow(int j) const
293  {
294  return m_data.getRow(j);
295  }
297  void set(int i, int j, bool v)
298  {
299  m_data.set(i,j, v);
300  }
302  void setRow(int j, bool const *val)
303  {
304  m_data.setRow(j, val);
305  }
307  void setRowPacked(int j, unsigned char const *val)
308  {
309  m_data.setRowPacked(j, val);
310  }
312  void setColumn(int i, bool const *val)
313  {
314  m_data.setColumn(i, val);
315  }
316 
317 protected:
319  virtual bool createFileData(librevenge::RVNGBinaryData &result) const;
320 
323 };
324 
327 {
328 public:
330  virtual SubType getSubType() const
331  {
332  return Indexed;
333  }
334 
337  virtual int cmp(MWAWPict const &a) const
338  {
339  int diff = MWAWPictBitmap::cmp(a);
340  if (diff) return diff;
341  MWAWPictBitmapIndexed const &aPict = static_cast<MWAWPictBitmapIndexed const &>(a);
342 
343  diff=int(m_colors.size())-int(aPict.m_colors.size());
344  if (diff) return (diff < 0) ? -1 : 1;
345  for (size_t c=0; c < m_colors.size(); c++) {
346  if (m_colors[c] < aPict.m_colors[c])
347  return 1;
348  if (m_colors[c] > aPict.m_colors[c])
349  return -1;
350  }
351  return m_data.cmp(aPict.m_data);
352  }
353 
355  virtual bool valid() const
356  {
357  return m_data.ok();
358  }
359 
362 
364  Vec2i const &size() const
365  {
366  return m_data.size();
367  }
369  int numRows() const
370  {
371  return m_data.numRows();
372  }
374  int numColumns() const
375  {
376  return m_data.numColumns();
377  }
379  int get(int i, int j) const
380  {
381  return m_data.get(i,j);
382  }
384  int const *getRow(int j) const
385  {
386  return m_data.getRow(j);
387  }
388 
390  void set(int i, int j, int v)
391  {
392  m_data.set(i,j, v);
393  }
395  template <class U> void setRow(int j, U const *val)
396  {
397  m_data.setRow(j, val);
398  }
400  template <class U> void setColumn(int i, U const *val)
401  {
402  m_data.setColumn(i, val);
403  }
404 
406  std::vector<MWAWColor> const &getColors() const
407  {
408  return m_colors;
409  }
411  void setColors(std::vector<MWAWColor> const &cols)
412  {
413  m_colors = cols;
414  }
415 
416 protected:
418  virtual bool createFileData(librevenge::RVNGBinaryData &result) const;
419 
423  std::vector<MWAWColor> m_colors;
424 };
425 
428 {
429 public:
431  virtual SubType getSubType() const
432  {
433  return Indexed;
434  }
435 
438  virtual int cmp(MWAWPict const &a) const
439  {
440  int diff = MWAWPictBitmap::cmp(a);
441  if (diff) return diff;
442  MWAWPictBitmapColor const &aPict = static_cast<MWAWPictBitmapColor const &>(a);
443 
444  return m_data.cmp(aPict.m_data);
445  }
446 
448  virtual bool valid() const
449  {
450  return m_data.ok();
451  }
452 
454  MWAWPictBitmapColor(Vec2i const &sz) : MWAWPictBitmap(sz), m_data(sz) { }
455 
457  Vec2i const &size() const
458  {
459  return m_data.size();
460  }
462  int numRows() const
463  {
464  return m_data.numRows();
465  }
467  int numColumns() const
468  {
469  return m_data.numColumns();
470  }
472  MWAWColor get(int i, int j) const
473  {
474  return m_data.get(i,j);
475  }
477  MWAWColor const *getRow(int j) const
478  {
479  return m_data.getRow(j);
480  }
481 
483  void set(int i, int j, MWAWColor const &v)
484  {
485  m_data.set(i,j, v);
486  }
488  void setRow(int j, MWAWColor const *val)
489  {
490  m_data.setRow(j, val);
491  }
493  void setColumn(int i, MWAWColor const *val)
494  {
495  m_data.setColumn(i, val);
496  }
497 
498 protected:
500  virtual bool createFileData(librevenge::RVNGBinaryData &result) const;
501 
504 };
505 #endif
506 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
void setColumn(int i, bool const *val)
sets all cell contents of a column
Definition: MWAWPictBitmap.hxx:312
Definition: MWAWPictBitmap.hxx:190
int numColumns() const
gets the number of column
Definition: MWAWPictBitmap.hxx:98
void set(int i, int j, MWAWColor const &v)
sets a cell contents
Definition: MWAWPictBitmap.hxx:483
T * m_data
the m_data placed by row ie. d_00, d_10, ... , d_{X-1}0, ..
Definition: MWAWPictBitmap.hxx:146
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:217
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:448
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:438
Definition: MWAWPictBitmap.hxx:190
Vec2i const & size() const
the picture size
Definition: MWAWPictBitmap.hxx:272
Vec2< float > Vec2f
Vec2 of float.
Definition: libmwaw_internal.hxx:660
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:263
void setColumn(int i, U const *val)
sets a column of m_data
Definition: MWAWPictBitmap.hxx:133
int numRows() const
the number of rows
Definition: MWAWPictBitmap.hxx:462
void setRow(int j, U const *val)
sets a line of m_data
Definition: MWAWPictBitmap.hxx:125
void set(int i, int j, T const &v)
sets a cell m_data
Definition: MWAWPictBitmap.hxx:117
void setColumn(int i, U const *val)
sets all cell contents of a column
Definition: MWAWPictBitmap.hxx:400
MWAWPictBitmap(Vec2i const &sz)
protected constructor: use check to construct a picture
Definition: MWAWPictBitmap.hxx:235
void setRow(int j, MWAWColor const *val)
sets all cell contents of a row
Definition: MWAWPictBitmap.hxx:488
virtual SubType getSubType() const =0
returns the picture subtype
Definition: MWAWPictBitmap.hxx:190
Vec2i m_size
the size
Definition: MWAWPictBitmap.hxx:144
Vec2i const & size() const
the picture size
Definition: MWAWPictBitmap.hxx:457
Box2< float > Box2f
Box2 of float.
Definition: libmwaw_internal.hxx:1022
the class to store a color
Definition: libmwaw_internal.hxx:166
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:102
T const & get(int i, int j) const
accessor of a cell m_data
Definition: MWAWPictBitmap.hxx:104
a bitmap of Vec3u to store true color bitmap
Definition: MWAWPictBitmap.hxx:427
int const * getRow(int j) const
returns the cells content of a row
Definition: MWAWPictBitmap.hxx:384
int numColumns() const
the number of columns
Definition: MWAWPictBitmap.hxx:282
int numRows() const
the number of rows
Definition: MWAWPictBitmap.hxx:277
a template class to store a 2D array of m_data
Definition: MWAWPictBitmap.hxx:54
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:355
void setRow(int j, bool const *val)
sets all cell contents of a row
Definition: MWAWPictBitmap.hxx:302
int numRows() const
gets the number of row
Definition: MWAWPictBitmap.hxx:93
std::vector< MWAWColor > const & getColors() const
returns the array of indexed colors
Definition: MWAWPictBitmap.hxx:406
a bitmap of bool to store black-white bitmap
Definition: MWAWPictBitmap.hxx:242
bool const * getRow(int j) const
returns the cells content of a row
Definition: MWAWPictBitmap.hxx:292
void set(int i, int j, int v)
sets a cell contents
Definition: MWAWPictBitmap.hxx:390
SubType
the picture subtype: blackwhite, indexed, color
Definition: MWAWPictBitmap.hxx:190
a bool container with a function to put packed row
Definition: MWAWPictBitmap.hxx:150
void set(int i, int j, bool v)
sets a cell contents
Definition: MWAWPictBitmap.hxx:297
MWAWPictBitmapIndexed(Vec2i const &sz)
the constructor
Definition: MWAWPictBitmap.hxx:361
a bitmap of int to store indexed bitmap
Definition: MWAWPictBitmap.hxx:326
void setColors(std::vector< MWAWColor > const &cols)
sets the array of indexed colors
Definition: MWAWPictBitmap.hxx:411
MWAWPictBitmapContainer< int > m_data
the m_data
Definition: MWAWPictBitmap.hxx:421
void setBdBox(Box2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:85
virtual bool createFileData(librevenge::RVNGBinaryData &result) const
function which creates the result file
Definition: MWAWPictBitmap.cxx:134
Type
the different picture types:
Definition: MWAWPict.hxx:64
int cmp(MWAWPictBitmapContainerBool const &orig) const
a comparison operator
Definition: MWAWPictBitmap.hxx:157
virtual bool getBinary(librevenge::RVNGBinaryData &res, std::string &s) const
returns the final librevenge::RVNGBinary data
Definition: MWAWPictBitmap.hxx:200
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libmwaw_internal.hxx:604
MWAWPictBitmapContainer & operator=(MWAWPictBitmapContainer const &orig)
void setRowPacked(int j, unsigned char const *val)
allows to use packed m_data
Definition: MWAWPictBitmap.hxx:171
MWAWColor const * getRow(int j) const
returns the cells content of a row
Definition: MWAWPictBitmap.hxx:477
void setRow(int j, U const *val)
sets all cell contents of a row
Definition: MWAWPictBitmap.hxx:395
virtual bool createFileData(librevenge::RVNGBinaryData &result) const =0
abstract function which creates the result file
MWAWPictBitmapContainerBool(Vec2i const &sz)
constructor
Definition: MWAWPictBitmap.hxx:154
virtual ~MWAWPictBitmapContainer()
destructor
Definition: MWAWPictBitmap.hxx:63
virtual bool createFileData(librevenge::RVNGBinaryData &result) const
the function which creates the result file
Definition: MWAWPictBitmap.cxx:152
Generic class used to construct bitmap.
Definition: MWAWPictBitmap.hxx:186
int numColumns() const
the number of columns
Definition: MWAWPictBitmap.hxx:467
int cmp(MWAWPictBitmapContainer< T > const &orig) const
a comparison operator
Definition: MWAWPictBitmap.hxx:75
bool ok() const
returns ok, if the m_data is allocated
Definition: MWAWPictBitmap.hxx:69
int numRows() const
the number of rows
Definition: MWAWPictBitmap.hxx:369
MWAWPictBitmapColor(Vec2i const &sz)
the constructor
Definition: MWAWPictBitmap.hxx:454
T const * getRow(int j) const
accessor of a row m_data
Definition: MWAWPictBitmap.hxx:110
void setColumn(int i, MWAWColor const *val)
sets all cell contents of a column
Definition: MWAWPictBitmap.hxx:493
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:210
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:253
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictBitmap.hxx:246
MWAWPictBitmapContainer(Vec2i const &sz)
constructor given size
Definition: MWAWPictBitmap.hxx:58
Definition: MWAWPict.hxx:64
virtual bool createFileData(librevenge::RVNGBinaryData &result) const
the function which creates the result file
Definition: MWAWPictBitmap.cxx:143
std::vector< MWAWColor > m_colors
the colors
Definition: MWAWPictBitmap.hxx:423
virtual SubType getSubType() const
return the picture subtype
Definition: MWAWPictBitmap.hxx:330
virtual Type getType() const
returns the picture type
Definition: MWAWPictBitmap.hxx:192
virtual SubType getSubType() const
return the picture subtype
Definition: MWAWPictBitmap.hxx:431
void setRowPacked(int j, unsigned char const *val)
sets all cell contents of a row given packed m_data
Definition: MWAWPictBitmap.hxx:307
int numColumns() const
the number of columns
Definition: MWAWPictBitmap.hxx:374
MWAWPictBitmapContainer< MWAWColor > m_data
the data
Definition: MWAWPictBitmap.hxx:503
Vec2i const & size() const
return the array size
Definition: MWAWPictBitmap.hxx:88
MWAWPictBitmapBW(Vec2i const &sz)
the constructor
Definition: MWAWPictBitmap.hxx:269
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:52
Vec2i const & size() const
the picture size
Definition: MWAWPictBitmap.hxx:364
MWAWPictBitmapContainerBool m_data
the data
Definition: MWAWPictBitmap.hxx:322
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:337

Generated for libmwaw by doxygen 1.8.8