TuttleOFX
1
|
00001 #ifndef TUTTLE_HOST_CORE_IMAGE_HPP 00002 #define TUTTLE_HOST_CORE_IMAGE_HPP 00003 00004 #include <tuttle/host/ofx/OfxhImage.hpp> 00005 #include <tuttle/common/ofx/imageEffect.hpp> 00006 00007 #include <tuttle/host/memory/IMemoryPool.hpp> 00008 00009 /// @tuttle: remove include dependencies to gil 00010 #include <boost/gil/channel_algorithm.hpp> // force include boostHack first 00011 #include <boost/gil/image_view.hpp> 00012 #include <boost/gil/image_view_factory.hpp> 00013 00014 #include <boost/cstdint.hpp> 00015 00016 namespace tuttle { 00017 namespace host { 00018 namespace attribute { 00019 00020 class ClipImage; 00021 00022 /** 00023 * make an image up 00024 */ 00025 class Image : public tuttle::host::ofx::imageEffect::OfxhImage 00026 { 00027 public: 00028 enum EImageOrientation 00029 { 00030 eImageOrientationFromTopToBottom, //< Use image orientation from top to bottom 00031 eImageOrientationFromBottomToTop //< Use image orientation from bottom to top 00032 }; 00033 00034 protected: 00035 std::size_t _memorySize; ///< memory size 00036 std::size_t _pixelBytes; ///< pixel memory size 00037 int _rowAbsDistanceBytes; ///< positive memory size for the distance between rows 00038 OfxRectI _bounds; 00039 EImageOrientation _orientation; 00040 std::string _fullname; 00041 memory::IPoolDataPtr _data; ///< where we are keeping our image data 00042 00043 public: 00044 Image( ClipImage& clip, const OfxTime time, const OfxRectD& bounds, const EImageOrientation orientation, const int rowDistanceBytes ); 00045 virtual ~Image(); 00046 00047 #ifndef SWIG 00048 void setPoolData( const memory::IPoolDataPtr& pData ) 00049 { 00050 _data = pData; 00051 setPointerProperty( kOfxImagePropData, getOrientedPixelData( eImageOrientationFromBottomToTop ) ); // OpenFX standard use BottomToTop 00052 } 00053 #endif 00054 00055 std::string getFullName() const { return _fullname; } 00056 00057 std::size_t getMemorySize() const { return _memorySize; } 00058 /** 00059 * @brief Positive/Absolute distance rows. 00060 */ 00061 int getRowAbsDistanceBytes() const { return _rowAbsDistanceBytes; } 00062 00063 EImageOrientation getOrientation() const { return _orientation; } 00064 00065 std::size_t getNbComponents() const { return ofx::imageEffect::numberOfComponents( getComponentsType() ); } 00066 00067 /** 00068 * @brief Get distance between rows depending on the requested orientation. 00069 */ 00070 int getOrientedRowDistanceBytes( const EImageOrientation orientation ) { return _rowAbsDistanceBytes * ( _orientation != orientation ? -1 : 1); } 00071 00072 boost::uint8_t* getPixelData(); 00073 void* getVoidPixelData(); 00074 char* getCharPixelData(); 00075 boost::uint8_t* getOrientedPixelData( const EImageOrientation orientation ); 00076 00077 boost::uint8_t* pixel( const int x, const int y ); 00078 00079 /** 00080 * @todo clean this! 00081 * move outside from class or use copyFrom (don't specify dst) 00082 * use ref, change order, etc. 00083 */ 00084 static void copy( Image* dst, Image* src, const OfxPointI& dstCorner, 00085 const OfxPointI& srcCorner, const OfxPointI& count ); 00086 00087 void getImage( boost::uint8_t*& outData, int& outWidth, int& outHeight, int& outRowSizeBytes, ofx::imageEffect::EBitDepth& outBitDepth, ofx::imageEffect::EPixelComponent& outComponents ) 00088 { 00089 outData = getPixelData(); 00090 const OfxRectI bounds = getBounds(); 00091 outWidth = bounds.x2 - bounds.x1; 00092 outHeight = bounds.y2 - bounds.y1; 00093 outRowSizeBytes = getRowBytes(); 00094 outBitDepth = getBitDepth(); 00095 outComponents = getComponentsType(); 00096 } 00097 00098 00099 template < class VIEW_T > 00100 VIEW_T getGilView( const EImageOrientation orientation ); 00101 00102 template < class VIEW_T > 00103 VIEW_T getGilView(); 00104 00105 public: 00106 #ifndef TUTTLE_PRODUCTION 00107 #ifdef TUTTLE_PNG_EXPORT_BETWEEN_NODES 00108 void debugSaveAsPng( const std::string& filename ); 00109 #endif 00110 #endif 00111 00112 private: 00113 template < class S_VIEW > 00114 static void copy( Image* dst, S_VIEW& src, const OfxPointI& dstCorner, 00115 const OfxPointI& srcCorner, const OfxPointI& count ); 00116 template < class D_VIEW, class S_VIEW > 00117 static void copy( D_VIEW& dst, S_VIEW& src, const OfxPointI& dstCorner, 00118 const OfxPointI& srcCorner, const OfxPointI& count ); 00119 }; 00120 00121 00122 template < class VIEW_T > 00123 VIEW_T Image::getGilView( const EImageOrientation orientation ) 00124 { 00125 //const OfxRectI rod = this->getROD(); 00126 const OfxRectI bounds = this->getBounds(); 00127 00128 TUTTLE_TLOG_VAR( TUTTLE_TRACE, bounds ); 00129 TUTTLE_TLOG_VAR( TUTTLE_TRACE, std::abs( bounds.x2 - bounds.x1 ) ); 00130 TUTTLE_TLOG_VAR( TUTTLE_TRACE, std::abs( bounds.y2 - bounds.y1 ) ); 00131 TUTTLE_TLOG_VAR( TUTTLE_TRACE, this->getRowBytes() ); 00132 00133 typedef typename VIEW_T::value_type Pixel; 00134 return boost::gil::interleaved_view( std::abs( bounds.x2 - bounds.x1 ), 00135 std::abs( bounds.y2 - bounds.y1 ), 00136 ( Pixel* )( this->getOrientedPixelData( orientation ) ), 00137 this->getOrientedRowDistanceBytes( orientation ) ); 00138 } 00139 00140 template < class VIEW_T > 00141 VIEW_T Image::getGilView() 00142 { 00143 //const OfxRectI rod = this->getROD(); 00144 const OfxRectI bounds = this->getBounds(); 00145 00146 typedef typename VIEW_T::value_type Pixel; 00147 return boost::gil::interleaved_view( std::abs( bounds.x2 - bounds.x1 ), 00148 std::abs( bounds.y2 - bounds.y1 ), 00149 ( Pixel* )( this->getPixelData() ), 00150 this->getRowAbsDistanceBytes() ); 00151 } 00152 00153 } 00154 } 00155 } 00156 00157 #endif