1 /* This file is part of the Pangolin Project. 2 * http://github.com/stevenlovegrove/Pangolin 3 * 4 * Copyright (c) 2014 Steven Lovegrove 5 * 6 * Permission is hereby granted, free of charge, to any person 7 * obtaining a copy of this software and associated documentation 8 * files (the "Software"), to deal in the Software without 9 * restriction, including without limitation the rights to use, 10 * copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following 13 * conditions: 14 * 15 * The above copyright notice and this permission notice shall be 16 * included in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * OTHER DEALINGS IN THE SOFTWARE. 26 */ 27 28 #pragma once 29 30 #include <pangolin/pangolin.h> 31 #include <pangolin/video/video.h> 32 33 namespace pangolin 34 { 35 36 // Enum to match libdc1394's dc1394_bayer_method_t 37 typedef enum { 38 BAYER_METHOD_NEAREST = 0, 39 BAYER_METHOD_SIMPLE, 40 BAYER_METHOD_BILINEAR, 41 BAYER_METHOD_HQLINEAR, 42 BAYER_METHOD_DOWNSAMPLE_, 43 BAYER_METHOD_EDGESENSE, 44 BAYER_METHOD_VNG, 45 BAYER_METHOD_AHD, 46 47 // Pangolin custom defines 48 BAYER_METHOD_NONE = 512, 49 BAYER_METHOD_DOWNSAMPLE, 50 BAYER_METHOD_DOWNSAMPLE_MONO 51 } bayer_method_t; 52 53 // Enum to match libdc1394's dc1394_color_filter_t 54 typedef enum { 55 DC1394_COLOR_FILTER_RGGB = 512, 56 DC1394_COLOR_FILTER_GBRG, 57 DC1394_COLOR_FILTER_GRBG, 58 DC1394_COLOR_FILTER_BGGR 59 } color_filter_t; 60 61 // Video class that debayers its video input using the given method. 62 class PANGOLIN_EXPORT DebayerVideo : 63 public VideoInterface, 64 public VideoFilterInterface, 65 public BufferAwareVideoInterface 66 { 67 public: 68 DebayerVideo(std::unique_ptr<VideoInterface>& videoin, const std::vector<bayer_method_t> &method, color_filter_t tile); 69 ~DebayerVideo(); 70 71 //! Implement VideoInput::Start() 72 void Start(); 73 74 //! Implement VideoInput::Stop() 75 void Stop(); 76 77 //! Implement VideoInput::SizeBytes() 78 size_t SizeBytes() const; 79 80 //! Implement VideoInput::Streams() 81 const std::vector<StreamInfo>& Streams() const; 82 83 //! Implement VideoInput::GrabNext() 84 bool GrabNext( unsigned char* image, bool wait = true ); 85 86 //! Implement VideoInput::GrabNewest() 87 bool GrabNewest( unsigned char* image, bool wait = true ); 88 89 std::vector<VideoInterface*>& InputStreams(); 90 91 static color_filter_t ColorFilterFromString(std::string str); 92 93 static bayer_method_t BayerMethodFromString(std::string str); 94 95 uint32_t AvailableFrames() const; 96 97 bool DropNFrames(uint32_t n); 98 99 protected: 100 void ProcessStreams(unsigned char* out, const unsigned char* in); 101 102 std::unique_ptr<VideoInterface> src; 103 std::vector<VideoInterface*> videoin; 104 std::vector<StreamInfo> streams; 105 106 size_t size_bytes; 107 std::unique_ptr<unsigned char[]> buffer; 108 109 std::vector<bayer_method_t> methods; 110 color_filter_t tile; 111 112 picojson::value device_properties; 113 picojson::value frame_properties; 114 }; 115 116 } 117