• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

to_qimage_nocopy.hh

00001 // Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00029 
00030 #ifndef MLN_CONVERT_TO_QIMAGE_NOCOPY_HH
00031 # define MLN_CONVERT_TO_QIMAGE_NOCOPY_HH
00032 
00033 # include <QtGui/QImage>
00034 
00035 # include <mln/core/concept/image.hh>
00036 # include <mln/geom/nrows.hh>
00037 # include <mln/geom/ncols.hh>
00038 # include <mln/border/resize.hh>
00039 
00040 
00041 # include <mln/value/qt/rgb32.hh>
00042 # include <mln/value/rgb8.hh>
00043 
00044 # if QT_VERSION < 0x040000
00045 #  error "Your version of Qt is too old and is not supported."
00046 # endif
00047 
00048 
00049 namespace mln
00050 {
00051 
00052   namespace convert
00053   {
00054 
00055     // Implementation
00056 
00057     namespace impl
00058     {
00059 
00060       template <typename I>
00061       inline
00062       QImage to_qimage_nocopy_qt_rgb32(const Image<I>& ima_)
00063       {
00064         const I& ima = exact(ima_);
00065         mln_precondition(ima.is_valid());
00066 
00067         const int
00068           nrows = geom::nrows(ima),
00069           ncols = geom::ncols(ima);
00070 
00071         typedef mln_value(I) V;
00072         QImage qima((uchar *)(&ima(ima.domain().pmin())), ncols, nrows,
00073                     (ncols + 2 * ima.border()) * sizeof(V),
00074                     QImage::Format_RGB32);
00075 
00076         return qima;
00077       }
00078 
00079 
00080 # if QT_VERSION >= 0x040400
00081 
00082       template <typename I>
00083       inline
00084       QImage to_qimage_nocopy_rgb8(const Image<I>& ima_)
00085       {
00086         const I& ima = exact(ima_);
00087         mln_precondition(ima.is_valid());
00088 
00089         const int
00090           nrows = geom::nrows(ima),
00091           ncols = geom::ncols(ima);
00092 
00093         typedef mln_value(I) V;
00094         QImage qima((uchar *)(&ima(ima.domain().pmin())), ncols, nrows,
00095                     (ncols + 2 * ima.border()) * sizeof(V),
00096                     QImage::Format_RGB888);
00097 
00098         return qima;
00099       }
00100 
00101 # endif
00102 
00103 
00104     } // end of namespace mln::convert::impl
00105 
00106 
00107 
00108 
00109     // Dispatch
00110 
00111     namespace internal
00112     {
00113 
00114       template <typename I>
00115       inline
00116       QImage to_qimage_nocopy_dispatch(const Image<I>& ima,
00117                                        const value::qt::rgb32&)
00118       {
00119         return impl::to_qimage_nocopy_qt_rgb32(ima);
00120       }
00121 
00122 
00123 # if QT_VERSION >= 0x040400
00124 
00125       template <typename I>
00126       inline
00127       QImage to_qimage_nocopy_dispatch(const Image<I>& ima,
00128                                        const value::rgb8&)
00129       {
00130         return impl::to_qimage_nocopy_rgb8(ima);
00131       }
00132 
00133 # endif
00134 
00135 
00136       template <typename I, typename V>
00137       inline
00138       QImage to_qimage_nocopy_dispatch(const Image<I>&, V&)
00139       {
00140         // Not supported yet!
00141         mlc_abort(I)::check();
00142         return QImage();
00143       }
00144 
00145 
00146       template <typename I>
00147       inline
00148       QImage to_qimage_nocopy_dispatch(const Image<I>& ima)
00149       {
00150         typedef mln_value(I) V;
00151         return to_qimage_nocopy_dispatch(ima, V());
00152       }
00153 
00154     } // end of namespace mln::convert::internal
00155 
00156 
00157 
00158     // Facade
00159 
00160     template <typename I>
00161     inline
00162     QImage to_qimage_nocopy(const Image<I>& ima_)
00163     {
00164       trace::entering("convert::to_qimage_nocopy");
00165 
00166       const I& ima = exact(ima_);
00167       mln_precondition(ima.is_valid());
00168 
00169       QImage output = internal::to_qimage_nocopy_dispatch(ima);
00170 
00171       trace::exiting("convert::to_qimage_nocopy");
00172       return output;
00173     }
00174 
00175 
00176   } // end of namespace mln::convert
00177 
00178 } // end of namespace mln
00179 
00180 #endif // ! MLN_CONVERT_TO_QIMAGE_NOCOPY_HH

Generated on Tue Oct 4 2011 15:24:42 for Milena (Olena) by  doxygen 1.7.1