TuttleOFX
1
|
00001 /* 00002 * Software License : 00003 * 00004 * Copyright (c) 2007-2009, The Open Effects Association Ltd. All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * Neither the name The Open Effects Association Ltd, nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00019 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00020 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00021 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00022 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00024 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00025 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00026 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00027 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 // ofx host 00031 #include "OfxhBinary.hpp" 00032 #include "OfxhImageEffectNode.hpp" 00033 #include "property/OfxhSet.hpp" 00034 #include "attribute/OfxhClip.hpp" 00035 00036 // ofx 00037 #include <ofxCore.h> 00038 00039 namespace tuttle { 00040 namespace host { 00041 namespace ofx { 00042 namespace imageEffect { 00043 00044 std::ptrdiff_t OfxhImage::_count = 0; 00045 00046 static property::OfxhPropSpec imageStuffs[] = { 00047 { kOfxPropType, property::ePropTypeString, 1, false, kOfxTypeImage }, 00048 { kOfxImageEffectPropPixelDepth, property::ePropTypeString, 1, true, kOfxBitDepthNone }, 00049 { kOfxImageEffectPropComponents, property::ePropTypeString, 1, true, kOfxImageComponentNone }, 00050 { kOfxImageEffectPropPreMultiplication, property::ePropTypeString, 1, true, kOfxImageOpaque }, 00051 { kOfxImageEffectPropRenderScale, property::ePropTypeDouble, 2, true, "1.0" }, 00052 { kOfxImagePropPixelAspectRatio, property::ePropTypeDouble, 1, true, "1.0" }, 00053 { kOfxImagePropData, property::ePropTypePointer, 1, true, NULL }, 00054 { kOfxImagePropBounds, property::ePropTypeInt, 4, true, "0" }, 00055 { kOfxImagePropRegionOfDefinition, property::ePropTypeInt, 4, true, "0", }, 00056 { kOfxImagePropRowBytes, property::ePropTypeInt, 1, true, "0", }, 00057 { kOfxImagePropField, property::ePropTypeString, 1, true, "", }, 00058 { kOfxImagePropUniqueIdentifier, property::ePropTypeString, 1, true, "" }, 00059 { 0 } 00060 }; 00061 00062 OfxhImage::OfxhImage() 00063 : property::OfxhSet( imageStuffs ) 00064 , _id( _count++ ) 00065 , _clipName( "No clip !" ) 00066 , _time( 0 ) 00067 { 00068 TUTTLE_LOG_TRACE( "[Ofxh Image] create clip:" << getClipName() 00069 << ", time:" << getTime() 00070 << ", id:" << getId() 00071 << ", ref host:" << getReferenceCount( ofx::imageEffect::OfxhImage::eReferenceOwnerHost ) 00072 << ", ref plugins:" << getReferenceCount( ofx::imageEffect::OfxhImage::eReferenceOwnerPlugin ) ); 00073 } 00074 00075 /** 00076 * make an image from a clip instance 00077 */ 00078 OfxhImage::OfxhImage( attribute::OfxhClip& instance, const OfxTime time ) 00079 : property::OfxhSet( imageStuffs ) 00080 , _id( _count++ ) 00081 , _clipName( instance.getFullName() ) 00082 , _time( time ) 00083 { 00084 TUTTLE_LOG_TRACE( "[Ofxh Image] create clip:" << getClipName() 00085 << ", time:" << getTime() 00086 << ", id:" << getId() 00087 << ", ref host:" << getReferenceCount( ofx::imageEffect::OfxhImage::eReferenceOwnerHost ) 00088 << ", ref plugins:" << getReferenceCount( ofx::imageEffect::OfxhImage::eReferenceOwnerPlugin ) ); 00089 initClipBits( instance ); 00090 } 00091 00092 /** 00093 * construction based on clip instance 00094 * 00095 OfxhImage::OfxhImage( attribute::OfxhClip& instance, 00096 OfxTime time, 00097 double renderScaleX, 00098 double renderScaleY, 00099 void* data, 00100 const OfxRectI& bounds, 00101 const OfxRectI& rod, 00102 int rowBytes, 00103 const std::string& field, 00104 const std::string& uniqueIdentifier ) 00105 : property::OfxhSet( imageStuffs ) 00106 , _id( _count++ ) 00107 , _clipName( instance.getName() ) 00108 , _time( time ) 00109 { 00110 TUTTLE_TLOG( TUTTLE_INFO, "++ OfxhImage, clipName:" << getClipName() 00111 << ", time:" << getTime() 00112 << ", id:" << getId() 00113 << ", ref host:" << getReferenceCount( ofx::imageEffect::OfxhImage::eReferenceOwnerHost ) 00114 << ", ref plugins:" << getReferenceCount( ofx::imageEffect::OfxhImage::eReferenceOwnerPlugin ) ); 00115 initClipBits( instance ); 00116 00117 // set other data 00118 setDoubleProperty( kOfxImageEffectPropRenderScale, renderScaleX, 0 ); 00119 setDoubleProperty( kOfxImageEffectPropRenderScale, renderScaleY, 1 ); 00120 setPointerProperty( kOfxImagePropData, data ); 00121 setIntProperty( kOfxImagePropBounds, bounds.x1, 0 ); 00122 setIntProperty( kOfxImagePropBounds, bounds.y1, 1 ); 00123 setIntProperty( kOfxImagePropBounds, bounds.x2, 2 ); 00124 setIntProperty( kOfxImagePropBounds, bounds.y2, 3 ); 00125 setIntProperty( kOfxImagePropRegionOfDefinition, rod.x1, 0 ); 00126 setIntProperty( kOfxImagePropRegionOfDefinition, rod.y1, 1 ); 00127 setIntProperty( kOfxImagePropRegionOfDefinition, rod.x2, 2 ); 00128 setIntProperty( kOfxImagePropRegionOfDefinition, rod.y2, 3 ); 00129 setIntProperty( kOfxImagePropRowBytes, rowBytes ); 00130 00131 setStringProperty( kOfxImagePropField, field ); 00132 setStringProperty( kOfxImageClipPropFieldOrder, field ); 00133 setStringProperty( kOfxImagePropUniqueIdentifier, uniqueIdentifier ); 00134 } 00135 */ 00136 00137 OfxhImage::~OfxhImage() 00138 { 00139 TUTTLE_LOG_TRACE( "[Ofxh Image] delete clip:" << getClipName() 00140 << ", time:" << getTime() 00141 << ", id:" << getId() 00142 << ", ref host:" << getReferenceCount( eReferenceOwnerHost ) 00143 << ", ref plugins:" << getReferenceCount( eReferenceOwnerPlugin ) ); 00144 // Ref count host/plugin, should be 0, but when an error occured 00145 // during the graph computation the ref count can be > 0. 00146 if( getReferenceCount( eReferenceOwnerHost ) ) 00147 { 00148 TUTTLE_LOG_INFO( "[Ofxh Image] The HOST has not properly released the image ref count (" 00149 << getReferenceCount(eReferenceOwnerHost) << ") of clip " << quotes(getClipName()) 00150 << " at time " << getTime() << "." ); 00151 } 00152 if( getReferenceCount( eReferenceOwnerPlugin ) ) 00153 { 00154 TUTTLE_LOG_INFO( "[Ofxh Image] The PLUGIN has not properly released the image ref count (" 00155 << getReferenceCount(eReferenceOwnerPlugin) << ") of clip " << quotes(getClipName()) 00156 << " at time " << getTime() << "." ); 00157 } 00158 } 00159 00160 /** 00161 * called during ctor to get bits from the clip props into ours 00162 */ 00163 void OfxhImage::initClipBits( attribute::OfxhClip& instance ) 00164 { 00165 const property::OfxhSet& clipProperties = instance.getProperties(); 00166 00167 // get and set the clip instance pixel depth 00168 const std::string& depth = clipProperties.getStringProperty( kOfxImageEffectPropPixelDepth ); 00169 00170 setStringProperty( kOfxImageEffectPropPixelDepth, depth ); 00171 00172 // get and set the clip instance components 00173 const std::string& comps = clipProperties.getStringProperty( kOfxImageEffectPropComponents ); 00174 setStringProperty( kOfxImageEffectPropComponents, comps ); 00175 00176 // get and set the clip instance premultiplication 00177 setStringProperty( kOfxImageEffectPropPreMultiplication, clipProperties.getStringProperty( kOfxImageEffectPropPreMultiplication ) ); 00178 00179 // get and set the clip instance pixel aspect ratio 00180 setDoubleProperty( kOfxImagePropPixelAspectRatio, clipProperties.getDoubleProperty( kOfxImagePropPixelAspectRatio ) ); 00181 } 00182 00183 OfxRectI OfxhImage::getBounds() const 00184 { 00185 OfxRectI bounds = {0, 0, 0, 0}; 00186 getIntPropertyN( kOfxImagePropBounds, &bounds.x1, 4 ); 00187 return bounds; 00188 } 00189 00190 OfxRectI OfxhImage::getROD() const 00191 { 00192 OfxRectI rod = {0, 0, 0, 0}; 00193 getIntPropertyN( kOfxImagePropRegionOfDefinition, &rod.x1, 4 ); 00194 return rod; 00195 } 00196 00197 EBitDepth OfxhImage::getBitDepth() const 00198 { 00199 std::string depth = getStringProperty( kOfxImageEffectPropPixelDepth ); 00200 EBitDepth bitDepth = eBitDepthNone; 00201 00202 if( depth == kOfxBitDepthByte ) 00203 { 00204 bitDepth = eBitDepthUByte; 00205 } 00206 else if( depth == kOfxBitDepthShort ) 00207 { 00208 bitDepth = eBitDepthUShort; 00209 } 00210 else if( depth == kOfxBitDepthFloat ) 00211 { 00212 bitDepth = eBitDepthFloat; 00213 } 00214 return bitDepth; 00215 } 00216 00217 EPixelComponent OfxhImage::getComponentsType() const 00218 { 00219 std::string sType = getStringProperty( kOfxImageEffectPropComponents ); 00220 EPixelComponent compType = ePixelComponentNone; 00221 00222 if( sType == kOfxImageComponentRGBA ) 00223 { 00224 compType = ePixelComponentRGBA; 00225 } 00226 else if( sType == kOfxImageComponentRGB ) 00227 { 00228 compType = ePixelComponentRGB; 00229 } 00230 else if( sType == kOfxImageComponentAlpha ) 00231 { 00232 compType = ePixelComponentAlpha; 00233 } 00234 return compType; 00235 } 00236 00237 int OfxhImage::getRowBytes() const 00238 { 00239 return getIntProperty( kOfxImagePropRowBytes ); 00240 } 00241 00242 int OfxhImage::getReferenceCount( const EReferenceOwner from ) const 00243 { 00244 RefMap::const_iterator it = _referenceCount.find(from); 00245 if( it == _referenceCount.end() ) 00246 return 0; 00247 return it->second; 00248 } 00249 00250 void OfxhImage::addReference( const EReferenceOwner from, const std::size_t n ) 00251 { 00252 const std::ptrdiff_t refC = _referenceCount[from] = getReferenceCount(from) + n; 00253 TUTTLE_TLOG( TUTTLE_INFO, "[Ofxh Image] add reference with degree " << n << ", clipName:" << getClipName() << ", time:" << getTime() << ", id:" << getId() << ", ref:" << refC ); 00254 } 00255 00256 bool OfxhImage::releaseReference( const EReferenceOwner from ) 00257 { 00258 const std::ptrdiff_t refC = _referenceCount[from] = getReferenceCount(from) - 1; 00259 TUTTLE_TLOG( TUTTLE_INFO, "[Ofxh Image] release reference, clipName:" << getClipName() << ", time:" << getTime() << ", id:" << getId() << ", ref:" << refC ); 00260 if( refC < 0 ) 00261 BOOST_THROW_EXCEPTION( std::logic_error( "Try to release an undeclared reference to an Image." ) ); 00262 return refC <= 0; 00263 } 00264 00265 } 00266 } 00267 } 00268 }