00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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 }
00105
00106
00107
00108
00109
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
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 }
00155
00156
00157
00158
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 }
00177
00178 }
00179
00180 #endif // ! MLN_CONVERT_TO_QIMAGE_NOCOPY_HH