$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
to_qimage_nocopy.hh
1 // Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
29 
30 #ifndef MLN_CONVERT_TO_QIMAGE_NOCOPY_HH
31 # define MLN_CONVERT_TO_QIMAGE_NOCOPY_HH
32 
33 # include <QtGui/QImage>
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/geom/nrows.hh>
37 # include <mln/geom/ncols.hh>
38 # include <mln/border/resize.hh>
39 
40 
41 # include <mln/value/qt/rgb32.hh>
42 # include <mln/value/rgb8.hh>
43 
44 # if QT_VERSION < 0x040000
45 # error "Your version of Qt is too old and is not supported."
46 # endif
47 
48 
49 namespace mln
50 {
51 
52  namespace convert
53  {
54 
55  // Implementation
56 
57  namespace impl
58  {
59 
60  template <typename I>
61  inline
62  QImage to_qimage_nocopy_qt_rgb32(const Image<I>& ima_)
63  {
64  const I& ima = exact(ima_);
65  mln_precondition(ima.is_valid());
66 
67  const int
68  nrows = geom::nrows(ima),
69  ncols = geom::ncols(ima);
70 
71  typedef mln_value(I) V;
72  QImage qima((uchar *)(&ima(ima.domain().pmin())), ncols, nrows,
73  (ncols + 2 * ima.border()) * sizeof(V),
74  QImage::Format_RGB32);
75 
76  return qima;
77  }
78 
79 
80 # if QT_VERSION >= 0x040400
81 
82  template <typename I>
83  inline
84  QImage to_qimage_nocopy_rgb8(const Image<I>& ima_)
85  {
86  const I& ima = exact(ima_);
87  mln_precondition(ima.is_valid());
88 
89  const int
90  nrows = geom::nrows(ima),
91  ncols = geom::ncols(ima);
92 
93  typedef mln_value(I) V;
94  QImage qima((uchar *)(&ima(ima.domain().pmin())), ncols, nrows,
95  (ncols + 2 * ima.border()) * sizeof(V),
96  QImage::Format_RGB888);
97 
98  return qima;
99  }
100 
101 # endif
102 
103 
104  } // end of namespace mln::convert::impl
105 
106 
107 
108 
109  // Dispatch
110 
111  namespace internal
112  {
113 
114  template <typename I>
115  inline
117  const value::qt::rgb32&)
118  {
120  }
121 
122 
123 # if QT_VERSION >= 0x040400
124 
125  template <typename I>
126  inline
127  QImage to_qimage_nocopy_dispatch(const Image<I>& ima,
128  const value::rgb8&)
129  {
130  return impl::to_qimage_nocopy_rgb8(ima);
131  }
132 
133 # endif
134 
135 
136  template <typename I, typename V>
137  inline
139  {
140  // Not supported yet!
141  mlc_abort(I)::check();
142  return QImage();
143  }
144 
145 
146  template <typename I>
147  inline
149  {
150  typedef mln_value(I) V;
151  return to_qimage_nocopy_dispatch(ima, V());
152  }
153 
154  } // end of namespace mln::convert::internal
155 
156 
157 
158  // Facade
159 
160  template <typename I>
161  inline
162  QImage to_qimage_nocopy(const Image<I>& ima_)
163  {
164  mln_trace("convert::to_qimage_nocopy");
165 
166  const I& ima = exact(ima_);
167  mln_precondition(ima.is_valid());
168 
169  QImage output = internal::to_qimage_nocopy_dispatch(ima);
170 
171  return output;
172  }
173 
174 
175  } // end of namespace mln::convert
176 
177 } // end of namespace mln
178 
179 #endif // ! MLN_CONVERT_TO_QIMAGE_NOCOPY_HH