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
00026 #include <mln/core/image/image2d.hh>
00027 #include <mln/win/rectangle2d.hh>
00028
00029 #include <mln/value/rgb8.hh>
00030
00031 #include <mln/io/ppm/load.hh>
00032 #include <mln/io/ppm/save.hh>
00033
00034 #include <mln/data/compare.hh>
00035
00036 #include "tests/data.hh"
00037
00038
00039 using namespace mln;
00040
00041 typedef value::rgb<23> rgb23;
00042
00043 struct to23bits : mln::Function_v2v<to23bits>
00044 {
00045
00046 typedef rgb23 result;
00047 result operator()(value::rgb8 v) const
00048 {
00049 result ret(v.red().to_enc() * 256,
00050 v.green().to_enc() * 256,
00051 v.blue().to_enc() * 256);
00052 return ret;
00053 }
00054 };
00055
00056 struct to8bits : mln::Function_v2v<to8bits>
00057 {
00058
00059 typedef value::rgb8 result;
00060 result operator()(rgb23 v) const
00061 {
00062 result ret(v.red().to_enc() / 256,
00063 v.green().to_enc() / 256,
00064 v.blue().to_enc() / 256);
00065 return ret;
00066 }
00067 };
00068
00069 int main()
00070 {
00071 using namespace mln;
00072 using value::rgb8;
00073
00074 typedef image2d<rgb8> I;
00075
00076
00077
00078 image2d<rgb8> a = io::ppm::load<rgb8>(MLN_IMG_DIR "/lena.ppm");
00079 image2d<rgb23> b(a.domain());
00080
00081 image2d<rgb8>::fwd_piter p(b.domain());
00082
00083
00084 to23bits f;
00085 for_all(p)
00086 b(p) = f(a(p));
00087 io::ppm::save(b, "out23.ppm");
00088
00089
00090 image2d<rgb23>
00091 c = io::ppm::load<rgb23>("out23.ppm");
00092 image2d<rgb8> d(a.domain());
00093
00094
00095
00096 to8bits g;
00097 for_all(p)
00098 d(p) = g(c(p));
00099 io::ppm::save(d, "out8.ppm");
00100
00101
00102 mln_assertion(d == a);
00103
00104 }