Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / doc / html / _downloads / affine.cpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #include <boost/gil.hpp>
9 #include <boost/gil/extension/io/jpeg.hpp>
10 #include <boost/gil/extension/numeric/sampler.hpp>
11 #include <boost/gil/extension/numeric/resample.hpp>
12
13 // Example for resample_pixels() in the numeric extension
14
15 int main()
16 {
17     namespace gil = boost::gil;
18
19     gil::rgb8_image_t img;
20     gil::read_image("test.jpg", img, gil::jpeg_tag());
21
22     // test resample_pixels
23     // Transform the image by an arbitrary affine transformation using nearest-neighbor resampling
24     gil::rgb8_image_t transf(gil::rgb8_image_t::point_t(gil::view(img).dimensions() * 2));
25     gil::fill_pixels(gil::view(transf), gil::rgb8_pixel_t(255, 0, 0)); // the background is red
26
27     gil::matrix3x2<double> mat =
28         gil::matrix3x2<double>::get_translate(-gil::point<double>(200,250)) *
29         gil::matrix3x2<double>::get_rotate(-15*3.14/180.0);
30     gil::resample_pixels(const_view(img), gil::view(transf), mat, gil::nearest_neighbor_sampler());
31     gil::write_view("out-affine.jpg", gil::view(transf), gil::jpeg_tag());
32
33     return 0;
34 }