Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lubomir Bourdev committed Sep 17, 2007
1 parent 6ba113b commit 2ad6747
Show file tree
Hide file tree
Showing 44 changed files with 2,497 additions and 901 deletions.
10 changes: 6 additions & 4 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
.SUFFIXES: .cpp
#CXX=/usr/local/gcc-411/bin/g++
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
BOOST_INCLUDE_PATH=-I../../.. -I../../../../boost_libraries
LIBJPEG_INCLUDE_PATH=-I../../../../lib/libjpeg
LIBJPEG_LIB_PATH=-L../../../../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
-rm -f out-interleaved_ptr.jpg out-x_gradient.jpg out-histogram.txt out-packed_pixel_bgr772.jpg out-packed_pixel_gray1.jpg out-dynamic_image.jpg
resize: resize.o
${CXX} -o resize ${CXX_FLAGS} resize.o ${LIBJPEG_LIB_PATH} -ljpeg
affine: affine.o
Expand Down
56 changes: 52 additions & 4 deletions example/convolution.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
Copyright 2005-2007 Adobe Systems Incorporated
Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/

/*************************************************************************************************/

///////////////////////
//// NOTE: This sample file uses the numeric extension, which does not come with the Boost distribution.
//// You may download it from http://opensource.adobe.com/gil
///////////////////////

/// \file
/// \brief Test file for convolve_rows() and convolve_cols() in the numeric extension
/// \author Lubomir Bourdev and Hailin Jin
Expand All @@ -18,17 +35,48 @@ int main() {
// 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};
// radius-1 Gaussian kernel, size 9
float gaussian_1[]={0.00022923296f,0.0059770769f,0.060597949f,0.24173197f,0.38292751f,
0.24173197f,0.060597949f,0.0059770769f,0.00022923296f};
/*
// radius-2 Gaussian kernel, size 15
float gaussian_2[]={
0.00048869418f,0.0024031631f,0.0092463447f,
0.027839607f,0.065602221f,0.12099898f,0.17469721f,
0.19744757f,
0.17469721f,0.12099898f,0.065602221f,0.027839607f,
0.0092463447f,0.0024031631f,0.00048869418f
};
//radius-3 Gaussian kernel, size 23
float gaussian_3[]={
0.00016944126f,0.00053842377f,0.0015324751f,0.0039068931f,
0.0089216027f,0.018248675f,0.033434924f,0.054872241f,
0.080666073f,0.10622258f,0.12529446f,
0.13238440f,
0.12529446f,0.10622258f,0.080666073f,
0.054872241f,0.033434924f,0.018248675f,0.0089216027f,
0.0039068931f,0.0015324751f,0.00053842377f,0.00016944126f
};
//radius-4 Gaussian kernel, size 29
float gaussian_4[]={
0.00022466264f,0.00052009715f,0.0011314391f,0.0023129794f,
0.0044433107f,0.0080211498f,0.013606987f,0.021691186f,
0.032493830f,0.045742013f,0.060509924f,0.075220309f,
0.087870099f,0.096459411f,0.099505201f,0.096459411f,0.087870099f,
0.075220309f,0.060509924f,0.045742013f,0.032493830f,
0.021691186f,0.013606987f,0.0080211498f,0.0044433107f,
0.0023129794f,0.0011314391f,0.00052009715f,0.00022466264f,
};
*/

kernel_1d_fixed<float,9> kernel(gaussian,4);
kernel_1d_fixed<float,9> kernel(gaussian_1,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);
kernel_1d<float> kernel2(gaussian_1,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));
Expand Down
12 changes: 12 additions & 0 deletions example/dynamic_image.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2005-2007 Adobe Systems Incorporated
Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/

/*************************************************************************************************/

/// \file
/// \brief Test file for using dynamic images
/// \author Lubomir Bourdev and Hailin Jin
Expand Down
12 changes: 12 additions & 0 deletions example/histogram.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2005-2007 Adobe Systems Incorporated
Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/

/*************************************************************************************************/

/// \file
/// \brief Example file to demonstrate a way to compute histogram
/// \author Lubomir Bourdev and Hailin Jin
Expand Down
16 changes: 14 additions & 2 deletions example/interleaved_ptr.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2005-2007 Adobe Systems Incorporated
Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/

/*************************************************************************************************/

/// \file
/// \brief Example file to demonstrate how to create a model of a pixel iterator
/// \author Lubomir Bourdev and Hailin Jin
Expand Down Expand Up @@ -32,7 +44,7 @@ int main(int argc, unsigned char* argv[])

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<MemoryBasedIteratorConcept<memory_based_step_iterator<rgb8_interleaved_ptr> > >();

boost::function_requires<MutablePixelConcept<rgb8_interleaved_ptr::value_type> >();
boost::function_requires<PixelConcept<rgb8c_interleaved_ptr::value_type> >();
Expand All @@ -51,7 +63,7 @@ int main(int argc, unsigned char* argv[])

// 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());
view(img).pixels().row_size());

// Apply view transformations and algorithms on it
jpeg_write_view("out-interleaved_ptr.jpg",nth_channel_view(flipped_up_down_view(src_view),1));
Expand Down
31 changes: 18 additions & 13 deletions example/interleaved_ptr.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/*
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)
Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/

/*************************************************************************************************/

////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -69,7 +74,7 @@ struct interleaved_ptr : public boost::iterator_facade<interleaved_ptr<ChannelP

/// 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));}
reference operator[](difference_type d) const { return memunit_advanced_ref(*this,d*sizeof(channel_t));}

// Put this for every iterator whose reference is a proxy type
reference operator->() const { return **this; }
Expand Down Expand Up @@ -152,32 +157,32 @@ struct channel_type<interleaved_ptr<ChannelPtr,Layout> > {
/////////////////////////////

template <typename ChannelPtr, typename Layout>
inline std::ptrdiff_t byte_step(const interleaved_ptr<ChannelPtr,Layout>&) {
inline std::ptrdiff_t memunit_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());
inline std::ptrdiff_t memunit_distance(const interleaved_ptr<ChannelPtr,Layout>& p1, const interleaved_ptr<ChannelPtr,Layout>& p2) {
return memunit_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);
inline void memunit_advance(interleaved_ptr<ChannelPtr,Layout>& p, std::ptrdiff_t diff) {
memunit_advance(p.channels(), diff);
}

template <typename ChannelPtr, typename Layout>
inline interleaved_ptr<ChannelPtr,Layout> byte_advanced(const interleaved_ptr<ChannelPtr,Layout>& p, std::ptrdiff_t byteDiff) {
inline interleaved_ptr<ChannelPtr,Layout> memunit_advanced(const interleaved_ptr<ChannelPtr,Layout>& p, std::ptrdiff_t diff) {
interleaved_ptr<ChannelPtr,Layout> ret=p;
byte_advance(ret, byteDiff);
memunit_advance(ret, diff);
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) {
inline typename interleaved_ptr<ChannelPtr,Layout>::reference memunit_advanced_ref(const interleaved_ptr<ChannelPtr,Layout>& p, std::ptrdiff_t diff) {
interleaved_ptr<ChannelPtr,Layout> ret=p;
byte_advance(ret, byteDiff);
memunit_advance(ret, diff);
return *ret;
}

Expand All @@ -187,7 +192,7 @@ inline typename interleaved_ptr<ChannelPtr,Layout>::reference byte_advanced_ref(

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

} } // namespace boost::gil
Expand Down
33 changes: 26 additions & 7 deletions example/interleaved_ref.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/*
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)
Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/

/*************************************************************************************************/


////////////////////////////////////////////////////////////////////////////////////////
/// \file
/// \brief Example on how to create a new model of a pixel reference
Expand Down Expand Up @@ -53,10 +59,6 @@ struct interleaved_ref {
// 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>(); }
Expand All @@ -65,7 +67,6 @@ struct interleaved_ref {
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; }
Expand All @@ -90,6 +91,24 @@ struct interleaved_ref {
template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,interleaved_ref> >(); }
};

// Required by ColorBaseConcept
template <typename ChannelReference, typename Layout, int K>
struct kth_element_type<interleaved_ref<ChannelReference,Layout>,K> {
typedef ChannelReference type;
};

template <typename ChannelReference, typename Layout, int K>
struct kth_element_reference_type<interleaved_ref<ChannelReference,Layout>,K> {
typedef ChannelReference type;
};

template <typename ChannelReference, typename Layout, int K>
struct kth_element_const_reference_type<interleaved_ref<ChannelReference,Layout>,K> {
typedef ChannelReference type;
// typedef typename channel_traits<ChannelReference>::const_reference type;
};


// Required by ColorBaseConcept
template <int K, typename ChannelReference, typename Layout>
typename element_reference_type<interleaved_ref<ChannelReference,Layout> >::type
Expand Down
52 changes: 37 additions & 15 deletions example/packed_pixel.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2005-2007 Adobe Systems Incorporated
Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/

/*************************************************************************************************/

/// \file
/// \brief Example file to show how to deal with packed pixels
/// \author Lubomir Bourdev and Hailin Jin
Expand All @@ -12,6 +24,12 @@
/// 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
///
/// This test file also demonstrates how to use bit-aligned images - these are images whose pixels themselves are not byte aligned.
/// For example, an rgb222 image has a pixel whose size is 6 bits. Bit-aligned images are more complicated than packed images. They
/// require a special proxy class to represent pixel reference and pixel iterator (packed images use C++ reference and C pointer respectively).
/// The alignment parameter in the constructor of bit-aligned images is in bit units. For example, if you want your bit-aligned image to have 4-byte
/// alignment of its rows use alignment of 32, not 4.
///
/// To demonstrate that image view transformations work on packed images, we save the result transposed.

#include <algorithm>
Expand All @@ -20,27 +38,31 @@
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));
////////////////////////////////
// define a bgr772 image. It is a "packed" image - its channels are not byte-aligned, but its pixels are.
////////////////////////////////

typedef packed_image3_type<uint16_t, 7,7,2, bgr_layout_t>::type bgr772_image_t;
bgr772_image_t bgr772_img(img.dimensions());
copy_and_convert_pixels(const_view(img),view(bgr772_img));

// 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_bgr772.jpg",color_converted_view<bgr8_pixel_t>(transposed_view(const_view(bgr772_img))));

////////////////////////////////
// define a gray1 image (one-bit per pixel). It is a "bit-aligned" image - its pixels are not byte aligned.
////////////////////////////////

typedef bit_aligned_image1_type<1, gray_layout_t>::type gray1_image_t;
gray1_image_t gray1_img(img.dimensions());
copy_and_convert_pixels(const_view(img),view(gray1_img));

// 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))));
jpeg_write_view("out-packed_pixel_gray1.jpg",color_converted_view<gray8_pixel_t>(transposed_view(const_view(gray1_img))));

return 0;
}
Loading

0 comments on commit 2ad6747

Please sign in to comment.