Update of /cvsroot/boost/boost/libs/gil/example
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv6007/gil/example

Added Files:
        Makefile README.txt affine.cpp convolution.cpp 
        dynamic_image.cpp histogram.cpp interleaved_ptr.cpp 
        interleaved_ptr.hpp interleaved_ref.hpp mandelbrot.cpp 
        packed_pixel.cpp resize.cpp test.jpg x_gradient.cpp 
Log Message:
Initial version of boost/libs/gil

--- NEW FILE: Makefile ---
CXX=g++
CXX_FLAGS=-Wall -O2 -DNDEBUG -DBOOST_GIL_USE_CONCEPT_CHECK

BOOST_INCLUDE_PATH=-I../../..
LIBJPEG_INCLUDE_PATH=-I../../../boost/gil/lib/libjpeg
LIBJPEG_LIB_PATH=-L../../../boost/gil/lib/libjpeg

all: resize affine convolution mandelbrot x_gradient histogram dynamic_image 
interleaved_ptr packed_pixel
.cpp.o:
        ${CXX} ${CXX_FLAGS} ${BOOST_INCLUDE_PATH} ${LIBJPEG_INCLUDE_PATH} -c $<
clean:
        -rm -f *.o *.exe 
        -rm -f out-affine.jpg out-resize.jpg out-convolution.jpg 
out-convolution2.jpg out-mandelbrot.jpg
        -rm -f out-interleaved_ptr.jpg out-x_gradient.jpg out-histogram.txt 
out-packed_pixel.jpg out-dynamic_image.jpg
resize: resize.o
        ${CXX} -o resize ${CXX_FLAGS} resize.o ${LIBJPEG_LIB_PATH} -ljpeg 
affine: affine.o
        ${CXX} -o affine ${CXX_FLAGS} affine.o ${LIBJPEG_LIB_PATH} -ljpeg
convolution:    convolution.o
        ${CXX} -o convolution ${CXX_FLAGS} convolution.o ${LIBJPEG_LIB_PATH} 
-ljpeg 
mandelbrot:     mandelbrot.o
        ${CXX} -o mandelbrot ${CXX_FLAGS} mandelbrot.o ${LIBJPEG_LIB_PATH} 
-ljpeg 
interleaved_ptr:        interleaved_ptr.o
        ${CXX} -o interleaved_ptr ${CXX_FLAGS} interleaved_ptr.o 
${LIBJPEG_LIB_PATH} -ljpeg 
interleaved_ptr.cpp:    interleaved_ptr.hpp
x_gradient:     x_gradient.o
        ${CXX} -o x_gradient ${CXX_FLAGS} x_gradient.o ${LIBJPEG_LIB_PATH} 
-ljpeg 
histogram:      histogram.o
        ${CXX} -o histogram ${CXX_FLAGS} histogram.o ${LIBJPEG_LIB_PATH} -ljpeg 
packed_pixel:   packed_pixel.o
        ${CXX} -o packed_pixel ${CXX_FLAGS} packed_pixel.o ${LIBJPEG_LIB_PATH} 
-ljpeg 
dynamic_image:  dynamic_image.o
        ${CXX} -o dynamic_image ${CXX_FLAGS} dynamic_image.o 
${LIBJPEG_LIB_PATH} -ljpeg 


--- NEW FILE: README.txt ---
This directory contains GIL sample code.

We provide a Makefile that compiles all examples. You will need to change it to 
specify the correct path to boost, gil, and libjpeg. Some of the examples 
include the GIL numeric extension, which you can get from:
http://opensource.adobe.com/gil/download.html

The makefile generates a separate executable for each test file. Each 
executable generates its output as "out-<example_name>.jpg". For example, the 
resize.cpp example generates the image out-resize.jpg

The following examples are included:

1. resize.cpp
   Scales an image using bilinear or nearest-neighbor resampling

2. affine.cpp
   Performs an arbitrary affine transformation on the image

3. convolution.cpp
   Convolves the image with a Gaussian kernel

4. mandelbrot.cpp
   Creates a synthetic image defining the Mandelbrot set

5. interleaved_ptr.cpp
   Illustrates how to create a custom pixel reference and iterator.
   Creates a GIL image view over user-supplied data without the need to cast to 
GIL pixel type

6. x_gradient.cpp
   Horizontal gradient, from the tutorial

7. histogram.cpp
   Algorithm to compute the histogram of an image

8. packed_pixel.cpp
   Illustrates how to create a custom pixel model - a pixel whose channel size 
is not divisible by bytes

9. dynamic_image.cpp
   Example of using images whose type is instantiated at run time



--- NEW FILE: affine.cpp ---
/// \file
/// \brief Test file for resample_pixels() in the numeric extension
/// \author Lubomir Bourdev and Hailin Jin
/// \date February 27, 2007

#include <boost/gil/image.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/numeric/sampler.hpp>
#include <boost/gil/extension/numeric/resample.hpp>

int main() {
    using namespace boost::gil;

    rgb8_image_t img;
    jpeg_read_image("test.jpg",img);

    // test resample_pixels
    // Transform the image by an arbitrary affine transformation using 
nearest-neighbor resampling
    rgb8_image_t transf(rgb8_image_t::point_t(view(img).dimensions()*2));
    fill_pixels(view(transf),rgb8_pixel_t(255,0,0));    // the background is red

    matrix3x2<double> mat = 
matrix3x2<double>::get_translate(-point2<double>(200,250)) *
                            matrix3x2<double>::get_rotate(-15*3.14/180.0);
    resample_pixels(const_view(img), view(transf), mat, 
nearest_neighbor_sampler());
    jpeg_write_view("out-affine.jpg", view(transf));

    return 0;
}

--- NEW FILE: convolution.cpp ---
/// \file
/// \brief Test file for convolve_rows() and convolve_cols() in the numeric 
extension
/// \author Lubomir Bourdev and Hailin Jin
/// \date February 27, 2007

#include <boost/gil/image.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/numeric/kernel.hpp>
#include <boost/gil/extension/numeric/convolve.hpp>

int main() {
    using namespace boost::gil;

    rgb8_image_t img;
    jpeg_read_image("test.jpg",img);

    // Convolve the rows and the columns of the image with a fixed kernel
    rgb8_image_t convolved(img);

    float 
gaussian[]={0.00022923296f,0.0059770769f,0.060597949f,0.24173197f,0.38292751f,
                      0.24173197f,0.060597949f,0.0059770769f,0.00022923296f};

    kernel_1d_fixed<float,9> kernel(gaussian,4);

    
convolve_rows_fixed<rgb32f_pixel_t>(const_view(convolved),kernel,view(convolved));
    
convolve_cols_fixed<rgb32f_pixel_t>(const_view(convolved),kernel,view(convolved));
    jpeg_write_view("out-convolution.jpg", view(convolved));

    // This is how to use a resizable kernel
    kernel_1d<float> kernel2(gaussian,9,4);
    convolve_rows<rgb32f_pixel_t>(const_view(img),kernel2,view(img));
    convolve_cols<rgb32f_pixel_t>(const_view(img),kernel2,view(img));
    jpeg_write_view("out-convolution2.jpg", view(img));

    return 0;
}

--- NEW FILE: dynamic_image.cpp ---
/// \file
/// \brief Test file for using dynamic images
/// \author Lubomir Bourdev and Hailin Jin
/// \date February 27, 2007

#include <boost/mpl/vector.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>

int main() {
    using namespace boost::gil;

    typedef boost::mpl::vector<gray8_image_t, rgb8_image_t, gray16_image_t, 
rgb16_image_t> my_images_t;

    any_image<my_images_t> dynamic_img;
    jpeg_read_image("test.jpg",dynamic_img);

    // Save the image upside down, preserving its native color space and 
channel depth
    
jpeg_write_view("out-dynamic_image.jpg",flipped_up_down_view(const_view(dynamic_img)));

    return 0;
}

--- NEW FILE: histogram.cpp ---
/// \file
/// \brief Example file to demonstrate a way to compute histogram
/// \author Lubomir Bourdev and Hailin Jin
/// \date February 27, 2007

#include <algorithm>
#include <fstream>
#include <boost/gil/image.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/color_convert.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>

using namespace boost::gil;

template <typename GrayView, typename R>
void gray_image_hist(const GrayView& img_view, R& hist) {
//    for_each_pixel(img_view,++lambda::var(hist)[lambda::_1]);
    for (typename GrayView::iterator it=img_view.begin(); it!=img_view.end(); 
++it)
        ++hist[*it];
}

template <typename V, typename R>
void get_hist(const V& img_view, R& hist) {
    gray_image_hist(color_converted_view<gray8_pixel_t>(img_view), hist);
}

int main() {
    rgb8_image_t img;
    jpeg_read_image("test.jpg",img);

    int histogram[256];
    std::fill(histogram,histogram+256,0);
    get_hist(const_view(img),histogram);

    std::fstream histo_file("out-histogram.txt",std::ios::out);
    for(std::size_t ii=0;ii<256;++ii)
        histo_file << histogram[ii] << std::endl;
    histo_file.close();

    return 0;
}

--- NEW FILE: interleaved_ptr.cpp ---
/// \file
/// \brief Example file to demonstrate how to create a model of a pixel iterator
/// \author Lubomir Bourdev and Hailin Jin
/// \date February 27, 2007

#ifdef WIN32
#define _CRT_SECURE_NO_DEPRECATE 1
#pragma warning(disable : 4244) // 
#pragma warning(disable : 4996) // MSFT declared it deprecated
#endif

// gcc doesn't compile unless we forward-declare at_c before we include gil...
namespace boost { namespace gil {
    template <typename ChannelReference, typename Layout> struct 
interleaved_ref;
    template <typename ColorBase> struct element_reference_type;

    template <int K, typename ChannelReference, typename Layout>
    typename element_reference_type<interleaved_ref<ChannelReference,Layout> 
>::type
    at_c(const interleaved_ref<ChannelReference,Layout>& p);
} }

#include <iostream>
#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>
#include "interleaved_ptr.hpp"

int main(int argc, unsigned char* argv[])
{
    using namespace boost::gil;

    typedef interleaved_ptr<unsigned char*, rgb_layout_t> rgb8_interleaved_ptr;
    typedef interleaved_ptr<const unsigned char*, rgb_layout_t> 
rgb8c_interleaved_ptr;

    boost::function_requires<MutablePixelIteratorConcept<rgb8_interleaved_ptr> 
>();
    boost::function_requires<PixelIteratorConcept<rgb8c_interleaved_ptr> >();
    
boost::function_requires<ByteAdvanceableIteratorConcept<byte_addressable_step_iterator<rgb8_interleaved_ptr>
 > >();

    
boost::function_requires<MutablePixelConcept<rgb8_interleaved_ptr::value_type> 
>();
    boost::function_requires<PixelConcept<rgb8c_interleaved_ptr::value_type> 
>();

    typedef type_from_x_iterator<rgb8_interleaved_ptr >::view_t 
rgb8_interleaved_view_t;
    typedef type_from_x_iterator<rgb8c_interleaved_ptr>::view_t 
rgb8c_interleaved_view_t;

    boost::function_requires<MutableImageViewConcept<rgb8_interleaved_view_t> 
>();
    boost::function_requires<ImageViewConcept<rgb8c_interleaved_view_t> >();

    rgb8_image_t img;
    jpeg_read_image("test.jpg", img);

    // Get a raw pointer to the RGB buffer
    unsigned char* raw_ptr=&view(img)[0][0];

    // Construct a view from it, without casting it to rgb8_pixel_t*
    rgb8_interleaved_view_t 
src_view=interleaved_view(img.width(),img.height(),rgb8_interleaved_ptr(raw_ptr),
                                                      
view(img).pixels().row_bytes());

    // Apply view transformations and algorithms on it
    
jpeg_write_view("out-interleaved_ptr.jpg",nth_channel_view(flipped_up_down_view(src_view),1));

    return 0;
}



--- NEW FILE: interleaved_ptr.hpp ---
/*
    Copyright 2005-2007 Adobe Systems Incorporated
    Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
    or a copy at http://opensource.adobe.com/licenses.html)
*/
/*************************************************************************************************/

////////////////////////////////////////////////////////////////////////////////////////
/// \file               
/// \brief Example on how to create a pixel iterator
/// \author Lubomir Bourdev and Hailin Jin \n
///         Adobe Systems Incorporated
/// \date 2005-2007 \n Last updated on February 26, 2007
///
/// Definitions of standard GIL channel models
///
////////////////////////////////////////////////////////////////////////////////////////

#ifndef GIL_INTERLEAVED_PTR_HPP
#define GIL_INTERLEAVED_PTR_HPP

#include <boost/gil/pixel_iterator.hpp>
#include "interleaved_ref.hpp"

namespace boost { namespace gil {

/////////////////////////////////////////////////////////////////////////
///
/// A model of an interleaved pixel iterator. Contains an iterator to the first 
channel of the current pixel
///
/// Models: 
///     MutablePixelIteratorConcept
///        PixelIteratorConcept
///           boost_concepts::RandomAccessTraversalConcept
///           PixelBasedConcept
///     HomogeneousPixelBasedConcept
///        PixelBasedConcept
///     ByteAdvanceableConcept
///     HasDynamicXStepTypeConcept
///
/////////////////////////////////////////////////////////////////////////

template <typename ChannelPtr,  // Models Channel Iterator (examples: unsigned 
char* or const unsigned char*)
          typename Layout>      // A layout (includes the color space and 
channel ordering)
struct interleaved_ptr : public  
boost::iterator_facade<interleaved_ptr<ChannelPtr,Layout>,
                                   pixel<typename 
std::iterator_traits<ChannelPtr>::value_type,Layout>,
                                   boost::random_access_traversal_tag,
                                   const interleaved_ref<typename 
std::iterator_traits<ChannelPtr>::reference,Layout> >
{
private:
    typedef boost::iterator_facade<interleaved_ptr<ChannelPtr,Layout>,
                                   pixel<typename 
std::iterator_traits<ChannelPtr>::value_type,Layout>,
                                   boost::random_access_traversal_tag,
                                   const interleaved_ref<typename 
std::iterator_traits<ChannelPtr>::reference,Layout> > parent_t;
    typedef typename std::iterator_traits<ChannelPtr>::value_type channel_t;
public:
    typedef typename parent_t::reference                  reference;
    typedef typename parent_t::difference_type            difference_type;

    interleaved_ptr() {}
    interleaved_ptr(const interleaved_ptr& ptr) : _channels(ptr._channels) {}
    template <typename CP> interleaved_ptr(const interleaved_ptr<CP,Layout>& 
ptr) : _channels(ptr._channels) {}

    interleaved_ptr(const ChannelPtr& channels) : _channels(channels) {}

    // Construct from a pointer to the reference type. Not required by concepts 
but important
    interleaved_ptr(reference* pix) : _channels(&((*pix)[0])) {}
    interleaved_ptr& operator=(reference* pix) { _channels=&((*pix)[0]); return 
*this; }

    /// For some reason operator[] provided by boost::iterator_facade returns a 
custom class that is convertible to reference
    /// We require our own reference because it is registered in iterator_traits
    reference operator[](difference_type d) const { return 
byte_advanced_ref(*this,d*sizeof(channel_t));}

    // Put this for every iterator whose reference is a proxy type
    reference operator->()                  const { return **this; }

    // Channels accessor (not required by any concept)
    const ChannelPtr& channels()            const { return _channels; }
          ChannelPtr& channels()                  { return _channels; }
    
    // Not required by concepts but useful
    static const std::size_t num_channels = mpl::size<typename 
Layout::color_space_t>::value;
private:
    ChannelPtr _channels;
    friend class boost::iterator_core_access;
    template <typename CP, typename L> friend struct interleaved_ptr;

    void increment()            { _channels+=num_channels; }
    void decrement()            { _channels-=num_channels; }
    void advance(ptrdiff_t d)   { _channels+=num_channels*d; }

    ptrdiff_t distance_to(const interleaved_ptr& it) const { return 
(it._channels-_channels)/num_channels; }
    bool equal(const interleaved_ptr& it) const { return 
_channels==it._channels; }

    reference dereference() const { return reference(_channels); }
};

/////////////////////////////
//  PixelIteratorConcept
/////////////////////////////

// To get from the channel pointer a channel pointer to const, we have to go 
through the channel traits, which take a model of channel
// So we can get a model of channel from the channel pointer via 
iterator_traits. Notice that we take the iterator_traits::reference and not
// iterator_traits::value_type. This is because sometimes multiple reference 
and pointer types share the same value type. An example of this is
// GIL's planar reference and iterator ("planar_pixel_reference" and 
"planar_pixel_iterator") which share the class "pixel" as the value_type. The
// class "pixel" is also the value type for interleaved pixel references. Here 
we are dealing with channels, not pixels, but the principles still apply.
template <typename ChannelPtr, typename Layout>
struct const_iterator_type<interleaved_ptr<ChannelPtr,Layout> > { 
private:
    typedef typename std::iterator_traits<ChannelPtr>::reference channel_ref_t;
    typedef typename channel_traits<channel_ref_t>::const_pointer 
channel_const_ptr_t;
public:
    typedef interleaved_ptr<channel_const_ptr_t,Layout> type; 
};

template <typename ChannelPtr, typename Layout>
struct iterator_is_mutable<interleaved_ptr<ChannelPtr,Layout> > : public 
boost::mpl::true_ {};
template <typename Channel, typename Layout>
struct iterator_is_mutable<interleaved_ptr<const Channel*,Layout> > : public 
boost::mpl::false_ {};

template <typename ChannelPtr, typename Layout>
struct is_iterator_adaptor<interleaved_ptr<ChannelPtr,Layout> > : public 
boost::mpl::false_ {};

/////////////////////////////
//  PixelBasedConcept
/////////////////////////////

template <typename ChannelPtr, typename Layout>
struct color_space_type<interleaved_ptr<ChannelPtr,Layout> > {
    typedef typename Layout::color_space_t type;
};

template <typename ChannelPtr, typename Layout>
struct channel_mapping_type<interleaved_ptr<ChannelPtr,Layout> > {
    typedef typename Layout::channel_mapping_t type;
};

template <typename ChannelPtr, typename Layout>
struct is_planar<interleaved_ptr<ChannelPtr,Layout> > : public mpl::false_ {};

/////////////////////////////
//  HomogeneousPixelBasedConcept
/////////////////////////////

template <typename ChannelPtr, typename Layout>
struct channel_type<interleaved_ptr<ChannelPtr,Layout> > {
    typedef typename std::iterator_traits<ChannelPtr>::value_type type;
};

/////////////////////////////
//  ByteAdvanceableConcept
/////////////////////////////

template <typename ChannelPtr, typename Layout>
inline std::ptrdiff_t byte_step(const interleaved_ptr<ChannelPtr,Layout>&) { 
    return sizeof(typename std::iterator_traits<ChannelPtr>::value_type)*   // 
size of each channel in bytes
           interleaved_ptr<ChannelPtr,Layout>::num_channels;                // 
times the number of channels
}

template <typename ChannelPtr, typename Layout>
inline std::ptrdiff_t byte_distance(const interleaved_ptr<ChannelPtr,Layout>& 
p1, const interleaved_ptr<ChannelPtr,Layout>& p2) { 
    return byte_distance(p1.channels(),p2.channels()); 
}

template <typename ChannelPtr, typename Layout>
inline void byte_advance(interleaved_ptr<ChannelPtr,Layout>& p, std::ptrdiff_t 
byte_diff) { 
    byte_advance(p.channels(), byte_diff);
}

template <typename ChannelPtr, typename Layout>
inline interleaved_ptr<ChannelPtr,Layout> byte_advanced(const 
interleaved_ptr<ChannelPtr,Layout>& p, std::ptrdiff_t byteDiff) {
    interleaved_ptr<ChannelPtr,Layout> ret=p;
    byte_advance(ret, byteDiff);
    return ret;
}

template <typename ChannelPtr, typename Layout>
inline typename interleaved_ptr<ChannelPtr,Layout>::reference 
byte_advanced_ref(const interleaved_ptr<ChannelPtr,Layout>& p, std::ptrdiff_t 
byteDiff) {
    interleaved_ptr<ChannelPtr,Layout> ret=p;
    byte_advance(ret, byteDiff);
    return *ret;
}

/////////////////////////////
//  HasDynamicXStepTypeConcept
/////////////////////////////

template <typename ChannelPtr, typename Layout>
struct dynamic_x_step_type<interleaved_ptr<ChannelPtr,Layout> > {
    typedef byte_addressable_step_iterator<interleaved_ptr<ChannelPtr,Layout> > 
type;
};

} }  // namespace boost::gil

#endif

--- NEW FILE: interleaved_ref.hpp ---
/*
    Copyright 2005-2007 Adobe Systems Incorporated
    Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
    or a copy at http://opensource.adobe.com/licenses.html)
*/
/*************************************************************************************************/

////////////////////////////////////////////////////////////////////////////////////////
/// \file               
/// \brief Example on how to create a new model of a pixel reference
/// \author Lubomir Bourdev and Hailin Jin \n
///         Adobe Systems Incorporated
/// \date 2005-2007 \n Last updated on February 26, 2007
//////
////////////////////////////////////////////////////////////////////////////////////////

#ifndef GIL_INTERLEAVED_REF_HPP
#define GIL_INTERLEAVED_REF_HPP

#include <boost/mpl/range_c.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>

namespace boost { namespace gil {


/////////////////////////////////////////////////////////////////////////
///
/// A model of an interleaved pixel reference. Holds a pointer to the first 
channel
/// MODELS: 
///    MutableHomogeneousPixelConcept
///       MutableHomogeneousColorBaseConcept
///           MutableColorBaseConcept 
///           HomogeneousColorBaseConcept
///               ColorBaseConcept
///    HomogeneousPixelBasedConcept
///       PixelBasedConcept
///
/// For planar reference proxies to work properly, all of their methods must be 
const-qualified
/// and their iterator's reference type must be const-qualified. 
/// Mutability of the reference proxy is part of its type (in this case, 
depends on the mutability of ChannelReference)
/////////////////////////////////////////////////////////////////////////

template <typename ChannelReference, // Models ChannelConcept. A channel 
reference, unsigned char& or const unsigned char& 
          typename Layout>           // A layout (includes the color space and 
channel ordering)
struct interleaved_ref {
private:
    typedef typename channel_traits<ChannelReference>::value_type      
channel_t;
    typedef typename channel_traits<ChannelReference>::reference       
channel_reference_t;
    typedef typename channel_traits<ChannelReference>::const_reference 
channel_const_reference_t;
    typedef typename channel_traits<ChannelReference>::pointer         
channel_pointer_t;
public:
// Required by ColorBaseConcept
    typedef Layout layout_t;

    // Type of each channel, and the result of constant and mutable 
at_c<K>(*this);
    template <int K> struct kth_element_type                 { typedef 
channel_t type; };
    template <int K> struct kth_element_const_reference_type { typedef 
channel_reference_t type; };

    // Copy construction from a compatible type. The copy constructor of 
references is shallow. The channels themselves are not copied.
    interleaved_ref(const interleaved_ref& p) : _channels(p._channels) {}
    template <typename P> interleaved_ref(const P& p) : _channels(p._channels) 
{ check_compatible<P>(); }

    template <typename P> bool operator==(const P& p)    const { 
check_compatible<P>(); return static_equal(*this,p); }
    template <typename P> bool operator!=(const P& p)    const { return 
!(*this==p); }

// Required by MutableColorBaseConcept
    template <int K> struct kth_element_reference_type       { typedef 
channel_reference_t type; };
    
    // Assignment from a compatible type 
    const interleaved_ref&  operator=(const interleaved_ref& p)  const { 
static_copy(p,*this); return *this; }
    template <typename P> const interleaved_ref& operator=(const P& p) const { 
check_compatible<P>(); static_copy(p,*this); return *this; }

// Required by PixelConcept
    typedef pixel<channel_t, layout_t> value_type;
    typedef interleaved_ref            reference;
    typedef interleaved_ref<channel_const_reference_t, layout_t> 
const_reference;
    static const bool is_mutable = channel_traits<ChannelReference>::is_mutable;

// Required by HomogeneousPixelConcept
    ChannelReference                   operator[](std::size_t i) const { return 
_channels[i]; }

// Custom constructor (not part of any concept)
    explicit interleaved_ref(channel_pointer_t channels) : _channels(channels) 
{}
// This is needed for the reference proxy to work properly
    const interleaved_ref*             operator->()              const { return 
this; }
private:
    channel_pointer_t _channels;

    template <typename Pixel> static void check_compatible() { 
gil_function_requires<PixelsCompatibleConcept<Pixel,interleaved_ref> >(); }
};

// Required by ColorBaseConcept
template <int K, typename ChannelReference, typename Layout>
typename element_reference_type<interleaved_ref<ChannelReference,Layout> >::type
at_c(const interleaved_ref<ChannelReference,Layout>& p) { return p[K]; };

// Required by HomogeneousColorBaseConcept
template <typename ChannelReference, typename Layout>
typename element_reference_type<interleaved_ref<ChannelReference,Layout> >::type
dynamic_at_c(const interleaved_ref<ChannelReference,Layout>& p, std::size_t n) 
{ return p[n]; };

namespace detail {
    struct swap_fn_t {
        template <typename T> void operator()(T& x, T& y) const {
            using std::swap;
            swap(x,y);
        }
    };
}

// Required by MutableColorBaseConcept. The default std::swap does not do the 
right thing for proxy references - it swaps the references, not the values
template <typename ChannelReference, typename Layout>
void swap(interleaved_ref<ChannelReference,Layout>& x, 
interleaved_ref<ChannelReference,Layout>& y) { 
    static_for_each(x,y,detail::swap_fn_t());
};

// Required by PixelConcept
template <typename ChannelReference, typename Layout>
struct is_pixel<interleaved_ref<ChannelReference,Layout> > : public 
boost::mpl::true_ {};


// Required by PixelBasedConcept
template <typename ChannelReference, typename Layout>
struct color_space_type<interleaved_ref<ChannelReference,Layout> > {
    typedef typename Layout::color_space_t type;
}; 

// Required by PixelBasedConcept
template <typename ChannelReference, typename Layout>
struct channel_mapping_type<interleaved_ref<ChannelReference,Layout> > {
    typedef typename Layout::channel_mapping_t type;
}; 

// Required by PixelBasedConcept
template <typename ChannelReference, typename Layout>
struct is_planar<interleaved_ref<ChannelReference,Layout> > : mpl::false_ {};

// Required by HomogeneousPixelBasedConcept
template <typename ChannelReference, typename Layout>
struct channel_type<interleaved_ref<ChannelReference,Layout> > {
    typedef typename channel_traits<ChannelReference>::value_type type;
}; 

} }  // namespace boost::gil

#endif

--- NEW FILE: mandelbrot.cpp ---
/// \file
/// \brief Test file for convolve_rows() and convolve_cols() in the numeric 
extension
/// \author Lubomir Bourdev and Hailin Jin
/// \date February 27, 2007

#include <boost/gil/image.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>

using namespace boost::gil;

// Models a Unary Function
template <typename P>   // Models PixelValueConcept
struct mandelbrot_fn {
    typedef point2<ptrdiff_t>    point_t;

    typedef mandelbrot_fn        const_t;
    typedef P                    value_type;
    typedef value_type           reference;
    typedef value_type           const_reference;
    typedef point_t              argument_type;
    typedef reference            result_type;
    BOOST_STATIC_CONSTANT(bool, is_mutable=false);

    value_type                    _in_color,_out_color;
    point_t                       _img_size;
    static const int MAX_ITER=100;        // max number of iterations

    mandelbrot_fn() {}
    mandelbrot_fn(const point_t& sz, const value_type& in_color, const 
value_type& out_color) : _in_color(in_color), _out_color(out_color), 
_img_size(sz) {}

    result_type operator()(const point_t& p) const {
        // normalize the coords to (-2..1, -1.5..1.5)
        // (actually make y -1.0..2 so it is asymmetric, so we can verify some 
view factory methods)
        double t=get_num_iter(point2<double>(p.x/(double)_img_size.x*3-2, 
p.y/(double)_img_size.y*3-1.0f));//1.5f));
        t=pow(t,0.2);

        value_type ret;
        for (int k=0; k<num_channels<P>::value; ++k)
            ret[k]=(typename channel_type<P>::type)(_in_color[k]*t + 
_out_color[k]*(1-t));
        return ret;
    }

private:
    double get_num_iter(const point2<double>& p) const {
        point2<double> Z(0,0);
        for (int i=0; i<MAX_ITER; ++i) {
            Z = point2<double>(Z.x*Z.x - Z.y*Z.y + p.x, 2*Z.x*Z.y + p.y);
            if (Z.x*Z.x + Z.y*Z.y > 4)
                return i/(double)MAX_ITER;
        }
        return 0;
    }
};

int main() {
    typedef mandelbrot_fn<rgb8_pixel_t> deref_t;
    typedef deref_t::point_t            point_t;
    typedef virtual_2d_locator<deref_t,false> locator_t;
    typedef image_view<locator_t> my_virt_view_t;

    boost::function_requires<PixelLocatorConcept<locator_t> >();
    gil_function_requires<StepIteratorConcept<locator_t::x_iterator> >();

    point_t dims(200,200);
    my_virt_view_t mandel(dims, locator_t(point_t(0,0), point_t(1,1), 
deref_t(dims, rgb8_pixel_t(255,0,255), rgb8_pixel_t(0,255,0))));
    jpeg_write_view("out-mandelbrot.jpg",mandel);

    return 0;
}


--- NEW FILE: packed_pixel.cpp ---
/// \file
/// \brief Example file to show how to deal with packed pixels
/// \author Lubomir Bourdev and Hailin Jin
/// \date February 27, 2007
///
/// This test file demonstrates how to use packed pixel formats in GIL. 
/// A "packed" pixel is a pixel whose channels are bit ranges.
/// Here we create an RGB image whose pixel has 16-bits, such as:
/// bits [0..6] are the blue channel
/// bits [7..13] are the green channel
/// bits [14..15] are the red channel
/// We read a regular 8-bit RGB image, convert it to packed BGR772, convert it 
back to 8-bit RGB and save it to a file.
/// Since the red channel is only two bits the color loss should be observable 
in the result
///
/// To demonstrate that image view transformations work on packed images, we 
save the result transposed.

#include <algorithm>
#include <boost/gil/extension/io/jpeg_io.hpp>

using namespace boost;
using namespace boost::gil;


// define a bgr772 image
typedef const packed_channel_reference<boost::uint16_t, 0,7,true> 
bgr772_channel0_t;
typedef const packed_channel_reference<boost::uint16_t, 7,7,true> 
bgr772_channel1_t;
typedef const packed_channel_reference<boost::uint16_t,14,2,true> 
bgr772_channel2_t;
typedef heterogeneous_packed_pixel<uint16_t, 
    mpl::vector3<bgr772_channel0_t,bgr772_channel1_t,bgr772_channel2_t>, 
bgr_layout_t> bgr772_pixel_t;
typedef image<bgr772_pixel_t,false> bgr772_image_t;

int main() {
    boost::function_requires<PixelValueConcept<bgr772_pixel_t> >();
    BOOST_STATIC_ASSERT((sizeof(bgr772_pixel_t)==2));

    bgr8_image_t img;
    jpeg_read_image("test.jpg",img);

    bgr772_image_t img_packed1(img.dimensions());
    copy_and_convert_pixels(const_view(img),view(img_packed1));

    // Save the result. JPEG I/O does not support the packed pixel format, so 
convert it back to 8-bit RGB
    
jpeg_write_view("out-packed_pixel.jpg",color_converted_view<bgr8_pixel_t>(transposed_view(const_view(img_packed1))));

    return 0;
}

--- NEW FILE: resize.cpp ---
/// \file
/// \brief Test file for resize_view() in the numeric extension
/// \author Lubomir Bourdev and Hailin Jin
/// \date February 27, 2007

#include <boost/gil/image.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/numeric/sampler.hpp>
#include <boost/gil/extension/numeric/resample.hpp>

int main() {
    using namespace boost::gil;

    rgb8_image_t img;
    jpeg_read_image("test.jpg",img);

    // test resize_view
    // Scale the image to 100x100 pixels using bilinear resampling
    rgb8_image_t square100x100(100,100);
    resize_view(const_view(img), view(square100x100), bilinear_sampler());
    jpeg_write_view("out-resize.jpg",const_view(square100x100));

    return 0;
}

--- NEW FILE: test.jpg ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: x_gradient.cpp ---
/// \file
/// \brief Example file to demonstrate a way to compute gradients along x-axis
/// \author Lubomir Bourdev and Hailin Jin
/// \date October 19, 2006

#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>

using namespace boost::gil;

template <typename Out>
struct halfdiff_cast_channels {
    template <typename T> Out operator()(const T& in1, const T& in2) const {
        return Out((in2-in1)/2);
    }
};


template <typename SrcView, typename DstView>
void x_gradient(const SrcView& src, const DstView& dst) {
    typedef typename channel_type<DstView>::type dst_channel_t;

    for (int y=0; y<src.height(); ++y) {
        typename SrcView::x_iterator src_it = src.row_begin(y);
        typename DstView::x_iterator dst_it = dst.row_begin(y);

        for (int x=1; x<src.width()-1; ++x) {
            static_transform(src_it[x-1], src_it[x+1], dst_it[x], 
                             halfdiff_cast_channels<dst_channel_t>());
        }
    }
}

template <typename SrcView, typename DstView>
void x_luminosity_gradient(const SrcView& src, const DstView& dst) {
    typedef pixel<typename channel_type<SrcView>::type, gray_layout_t> 
gray_pixel_t;
    x_gradient(color_converted_view<gray_pixel_t>(src), dst);
}

int main() {
    rgb8_image_t img;
    jpeg_read_image("test.jpg",img);
    
    gray8s_image_t img_out(img.dimensions());
    fill_pixels(view(img_out),bits8s(0));

    x_luminosity_gradient(const_view(img), view(img_out));
    
jpeg_write_view("out-x_gradient.jpg",color_converted_view<gray8_pixel_t>(const_view(img_out)));

    return 0;
}


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to