File: interleaved_ptr.cpp

package info (click to toggle)
boost1.55 1.55.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 487,824 kB
  • ctags: 673,349
  • sloc: cpp: 2,098,430; xml: 106,036; ansic: 46,744; python: 32,427; sh: 11,864; cs: 2,121; asm: 1,640; makefile: 984; perl: 714; yacc: 456; php: 132; fortran: 43; sql: 13; csh: 6
file content (74 lines) | stat: -rw-r--r-- 2,967 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
    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
/// \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<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> >();

    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_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));

    return 0;
}