TuttleOFX
1
|
00001 #include "Jpeg2000ReaderPlugin.hpp" 00002 #include <terry/typedefs.hpp> 00003 00004 namespace tuttle { 00005 namespace plugin { 00006 namespace jpeg2000 { 00007 namespace reader { 00008 00009 template<class View> 00010 Jpeg2000ReaderProcess<View>::Jpeg2000ReaderProcess( Jpeg2000ReaderPlugin &instance ) 00011 : ImageGilProcessor<View>( instance, eImageOrientationFromTopToBottom ) 00012 , _plugin( instance ) 00013 { 00014 this->setNoMultiThreading(); 00015 } 00016 00017 template<class View> 00018 Jpeg2000ReaderProcess<View>::~Jpeg2000ReaderProcess() 00019 { 00020 _plugin._reader.close(); 00021 } 00022 00023 template<class View> 00024 void Jpeg2000ReaderProcess<View>::setup( const OFX::RenderArguments& args ) 00025 { 00026 ImageGilProcessor<View>::setup( args ); 00027 00028 _params = _plugin.getProcessParams( args.time ); 00029 } 00030 00031 /** 00032 * @brief Function called by rendering thread each time a process must be done. 00033 * @param[in] procWindowRoW Processing window in RoW 00034 */ 00035 template<class View> 00036 void Jpeg2000ReaderProcess<View>::multiThreadProcessImages( const OfxRectI& procWindowRoW ) 00037 { 00038 using namespace boost::gil; 00039 00040 View dstView = this->_dstView; 00041 00042 switch(_plugin._reader.components()) 00043 { 00044 case 1: 00045 { 00046 switchLayoutCopy<gray_layout_t>( dstView ); 00047 break; 00048 } 00049 case 3: 00050 { 00051 switchLayoutCopy<rgb_layout_t>( dstView ); 00052 break; 00053 } 00054 case 4: 00055 { 00056 switchLayoutCopy<rgba_layout_t>( dstView ); 00057 break; 00058 } 00059 default: 00060 { 00061 break; 00062 } 00063 } 00064 } 00065 00066 template<class View> 00067 template<class Layout> 00068 void Jpeg2000ReaderProcess<View>::switchLayoutCopy( const View& dstView ) 00069 { 00070 using namespace boost::gil; 00071 00072 switch(_plugin._reader.precision()) 00073 { 00074 case 8: 00075 { 00076 typedef pixel<bits8, Layout > PixelT; 00077 switchPrecisionCopy<PixelT>( dstView ); 00078 break; 00079 } 00080 case 12: 00081 { 00082 typedef pixel<bits12, Layout > PixelT; 00083 switchPrecisionCopy<PixelT>( dstView ); 00084 break; 00085 } 00086 case 16: 00087 { 00088 typedef pixel<bits16, Layout > PixelT; 00089 switchPrecisionCopy<PixelT>( dstView ); 00090 break; 00091 } 00092 case 32: 00093 { 00094 typedef pixel<bits32, Layout > PixelT; 00095 switchPrecisionCopy<PixelT>( dstView ); 00096 break; 00097 } 00098 default: 00099 BOOST_THROW_EXCEPTION( exception::ImageFormat() 00100 << exception::user("Unhandled image precision!") ); 00101 break; 00102 } 00103 } 00104 00105 template<class View> 00106 template<class WorkingPixel> 00107 void Jpeg2000ReaderProcess<View>::switchPrecisionCopy( const View & dstView ) 00108 { 00109 using namespace boost::gil; 00110 tuttle::io::J2KReader & reader = _plugin._reader; 00111 int w = reader.width(); 00112 int h = reader.height(); 00113 00114 unsigned int *data[num_channels<WorkingPixel>::type::value]; 00115 for( int i = 0; i < num_channels<WorkingPixel>::type::value; ++i ) 00116 { 00117 data[i] = (unsigned int*)reader.compData(i); 00118 } 00119 WorkingPixel pix; 00120 00121 for( typename View::y_coord_t y = 0; y < h; ++y ) 00122 { 00123 typename View::x_iterator it = dstView.row_begin( y ); 00124 00125 for( typename View::x_coord_t x = 0; x < w; ++x ) 00126 { 00127 for(int i = 0; i < num_channels<WorkingPixel>::type::value; ++i) 00128 { 00129 pix[i] = *(data[i]); 00130 ++data[i]; 00131 } 00132 color_convert(pix, *it); 00133 ++it; 00134 } 00135 } 00136 } 00137 00138 } 00139 } 00140 } 00141 }