1 /*
2  * Software License Agreement (BSD License)
3  *
4  *  Point Cloud Library (PCL) - www.pointclouds.org
5  *  Copyright (c) 2011, Willow Garage, Inc.
6  *  Copyright (c) 2012-, Open Perception, Inc.
7  *
8  *  All rights reserved.
9  *
10  *  Redistribution and use in source and binary forms, with or without
11  *  modification, are permitted provided that the following conditions
12  *  are met:
13  *
14  *   * Redistributions of source code must retain the above copyright
15  *     notice, this list of conditions and the following disclaimer.
16  *   * Redistributions in binary form must reproduce the above
17  *     copyright notice, this list of conditions and the following
18  *     disclaimer in the documentation and/or other materials provided
19  *     with the distribution.
20  *   * Neither the name of the copyright holder(s) nor the names of its
21  *     contributors may be used to endorse or promote products derived
22  *     from this software without specific prior written permission.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  *  POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #pragma once
40 
41 #include <pcl/pcl_config.h>
42 #include <pcl/memory.h>
43 #ifdef HAVE_OPENNI
44 
45 #include <pcl/pcl_macros.h>
46 #include "openni_image.h"
47 
48 namespace openni_wrapper
49 {
50   /** \brief This class provides methods to fill a RGB or Grayscale image buffer from underlying Bayer pattern image.
51     * \author Suat Gedikli <gedikli@willowgarage.com>
52     * \ingroup io
53     */
54   class PCL_EXPORTS ImageBayerGRBG : public Image
55   {
56     public:
57       enum DebayeringMethod
58       {
59         Bilinear = 0,
60         EdgeAware,
61         EdgeAwareWeighted
62       };
63 
64       ImageBayerGRBG (pcl::shared_ptr<xn::ImageMetaData> image_meta_data, DebayeringMethod method) noexcept;
65       ~ImageBayerGRBG () noexcept;
66 
67       inline Encoding
getEncoding()68       getEncoding () const override
69       {
70         return (BAYER_GRBG);
71       }
72 
73       void fillRGB (unsigned width, unsigned height, unsigned char* rgb_buffer, unsigned rgb_line_step = 0) const override;
74       void fillGrayscale (unsigned width, unsigned height, unsigned char* gray_buffer, unsigned gray_line_step = 0) const override;
75       bool isResizingSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const override;
76       inline void setDebayeringMethod (const DebayeringMethod& method) noexcept;
77       inline DebayeringMethod getDebayeringMethod () const throw ();
78       inline static bool resizingSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height);
79 
80 
81     protected:
82       DebayeringMethod debayering_method_;
83   };
84 
85   void
setDebayeringMethod(const ImageBayerGRBG::DebayeringMethod & method)86   ImageBayerGRBG::setDebayeringMethod (const ImageBayerGRBG::DebayeringMethod& method) noexcept
87   {
88     debayering_method_ = method;
89   }
90 
91   ImageBayerGRBG::DebayeringMethod
getDebayeringMethod()92   ImageBayerGRBG::getDebayeringMethod () const throw ()
93   {
94     return debayering_method_;
95   }
96 
97   bool
resizingSupported(unsigned input_width,unsigned input_height,unsigned output_width,unsigned output_height)98   ImageBayerGRBG::resizingSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height)
99   {
100     return (output_width <= input_width && output_height <= input_height && input_width % output_width == 0 && input_height % output_height == 0 );
101   }
102 } // namespace
103 
104 #endif
105