예제 #1
0
/* set up and run a processor */
void
InvertPlugin::setupAndProcess(InvertBase &processor, const OFX::RenderArguments &args)
{
    // get a dst image
    std::auto_ptr<OFX::Image> dst(dstClip_->fetchImage(args.time));
    if (!dst.get()) {
        OFX::throwSuiteStatusException(kOfxStatFailed);
    }
    OFX::BitDepthEnum dstBitDepth       = dst->getPixelDepth();
    OFX::PixelComponentEnum dstComponents  = dst->getPixelComponents();

    // fetch main input image
    std::auto_ptr<OFX::Image> src(srcClip_->fetchImage(args.time));

    // make sure bit depths are sane
    if (src.get()) {
        OFX::BitDepthEnum    srcBitDepth      = src->getPixelDepth();
        OFX::PixelComponentEnum srcComponents = src->getPixelComponents();

        // see if they have the same depths and bytes and all
        if (srcBitDepth != dstBitDepth || srcComponents != dstComponents) {
            OFX::throwSuiteStatusException(kOfxStatErrImageFormat);
        }
    }

    // auto ptr for the mask.
    std::auto_ptr<OFX::Image> mask((getContext() != OFX::eContextFilter) ? maskClip_->fetchImage(args.time) : 0);

    // do we do masking
    if (getContext() != OFX::eContextFilter && maskClip_->isConnected()) {
        // say we are masking
        processor.doMasking(true);

        // Set it in the processor
        processor.setMaskImg(mask.get());
    }

    bool red, green, blue, alpha;
    _paramProcessR->getValueAtTime(args.time, red);
    _paramProcessG->getValueAtTime(args.time, green);
    _paramProcessB->getValueAtTime(args.time, blue);
    _paramProcessA->getValueAtTime(args.time, alpha);
    double mix;
    _mix->getValueAtTime(args.time, mix);
    bool maskInvert;
    _maskInvert->getValueAtTime(args.time, maskInvert);
    processor.setValues(red, green, blue, alpha, mix, maskInvert);

    // set the images
    processor.setDstImg(dst.get());
    processor.setSrcImg(src.get());

    // set the render window
    processor.setRenderWindow(args.renderWindow);

    // Call the base class process member, this will call the derived templated process code
    processor.process();
}
예제 #2
0
bool CropPlugin::getRegionOfDefinition( const OFX::RegionOfDefinitionArguments& args, OfxRectD& rod )
{
	OFX::BooleanParam* bop = fetchBooleanParam( kParamFillMode );

	if( bop->getValue() == false )
	{
		rod = getCropRect( args.time );
		return true;
	}
	return false;
}
예제 #3
0
파일: basic.cpp 프로젝트: igorepi/openfx
/* set up and run a processor */
void
BasicPlugin::setupAndProcess(ImageScalerBase &processor, const OFX::RenderArguments &args)
{
  // get a dst image
  std::auto_ptr<OFX::Image> dst(dstClip_->fetchImage(args.time));
  OFX::BitDepthEnum dstBitDepth       = dst->getPixelDepth();
  OFX::PixelComponentEnum dstComponents  = dst->getPixelComponents();

  // fetch main input image
  std::auto_ptr<OFX::Image> src(srcClip_->fetchImage(args.time));

  // make sure bit depths are sane
  if(src.get()) {
    OFX::BitDepthEnum    srcBitDepth      = src->getPixelDepth();
    OFX::PixelComponentEnum srcComponents = src->getPixelComponents();

    // see if they have the same depths and bytes and all
    if(srcBitDepth != dstBitDepth || srcComponents != dstComponents)
      throw int(1); // HACK!! need to throw an sensible exception here!
  }

  // auto ptr for the mask.
  // Should do this inside the if statement below but the MS compiler I have doesn't have
  // a 'reset' function on the auto_ptr class
  std::auto_ptr<OFX::Image> mask(getContext() != OFX::eContextFilter ? maskClip_->fetchImage(args.time) : 0);

  // do we do masking
  if(getContext() != OFX::eContextFilter) {
    // say we are masking
    processor.doMasking(true);

    // Set it in the processor 
    processor.setMaskImg(mask.get());
  }

  // get the scale parameter values...
  double r, g, b, a = aScale_->getValueAtTime(args.time);
  r = g = b = scale_->getValueAtTime(args.time);

  // see if the individual component scales are enabled
  if(componentScalesEnabled_->getValueAtTime(args.time)) {
    r *= rScale_->getValueAtTime(args.time);
    g *= gScale_->getValueAtTime(args.time);
    b *= bScale_->getValueAtTime(args.time);
  }

  // set the images
  processor.setDstImg(dst.get());
  processor.setSrcImg(src.get());


  // set the render window
  processor.setRenderWindow(args.renderWindow);

  // set the scales
  processor.setScales((float)r, (float)g, (float)b, (float)a);

  // Call the base class process member, this will call the derived templated process code
  processor.process();
}
예제 #4
0
bool
InvertPlugin::isIdentity(const RenderArguments &args, Clip * &identityClip, double &identityTime)
{
    bool red, green, blue, alpha;
    double mix;
    _paramProcessR->getValueAtTime(args.time, red);
    _paramProcessG->getValueAtTime(args.time, green);
    _paramProcessB->getValueAtTime(args.time, blue);
    _paramProcessA->getValueAtTime(args.time, alpha);
    _mix->getValueAtTime(args.time, mix);

    if (mix == 0. || (!red && !green && !blue && !alpha)) {
        identityClip = srcClip_;
        return true;
    } else {
        return false;
    }
}
예제 #5
0
파일: basic.cpp 프로젝트: igorepi/openfx
// set the enabledness of the individual component scales
void
BasicPlugin::setEnabledness(void)
{
  // the componet enabledness depends on the clip being RGBA and the param being true
  bool v = componentScalesEnabled_->getValue() && srcClip_->getPixelComponents() == OFX::ePixelComponentRGBA;

  // enable them
  rScale_->setEnabled(v);
  gScale_->setEnabled(v);
  bScale_->setEnabled(v);
  aScale_->setEnabled(v);
}
예제 #6
0
파일: basic.cpp 프로젝트: igorepi/openfx
// overridden is identity
bool
BasicPlugin:: isIdentity(const OFX::IsIdentityArguments &args, OFX::Clip * &identityClip, double &identityTime)
{
  // get the scale parameters
  double scale = scale_->getValueAtTime(args.time);
  double rScale = 1, gScale = 1, bScale = 1, aScale = 1;
  if(componentScalesEnabled_->getValueAtTime(args.time)) {
    rScale = rScale_->getValueAtTime(args.time);
    gScale = gScale_->getValueAtTime(args.time);
    bScale = bScale_->getValueAtTime(args.time);
    aScale = aScale_->getValueAtTime(args.time);
  }
  rScale *= scale; gScale *= scale; bScale *= scale;

  // do we do any scaling ?
  if(rScale == 1 && gScale == 1 && bScale == 1 && aScale == 1) {
    identityClip = srcClip_;
    identityTime = args.time;
    return true;
  }

  // nope, idenity we is
  return false;
}
예제 #7
0
파일: util.cpp 프로젝트: edubois/TuttleOFX
bool LibAVParams::setOption( const std::string& libAVOptionName, const std::string& value, const std::string& detailedName )
{
	try
	{
		// Get libav option
		avtranscoder::Option& option = getLibAVOption( libAVOptionName, detailedName );

		// Set libav option's value
		option.setString( value );

		// Get corresponding OFX parameter
		OFX::ValueParam* param = getOFXParameter( libAVOptionName, detailedName );
		if( ! param)
		{
			TUTTLE_LOG_WARNING( "Can't get OFX parameter corresponding to option " << libAVOptionName << " of subgroup " << detailedName );
			return false;
		}

		// Set OFX parameter's value
		OFX::BooleanParam* paramBoolean = dynamic_cast<OFX::BooleanParam*>( param );
		if( paramBoolean )
		{
			paramBoolean->setValue( option.getBool() );
			return true;
		}
		OFX::IntParam* paramInt = dynamic_cast<OFX::IntParam*>( param );
		if( paramInt )
		{
			paramInt->setValue( option.getInt() );
			return true;
		}
		OFX::DoubleParam* paramDouble = dynamic_cast<OFX::DoubleParam*>( param );
		if( paramDouble )
		{
			paramDouble->setValue( option.getDouble() );
			return true;
		}
		OFX::StringParam* paramString = dynamic_cast<OFX::StringParam*>( param );
		if( paramString )
		{
			paramString->setValue( option.getString() );
			return true;
		}
		OFX::Int2DParam* paramRatio = dynamic_cast<OFX::Int2DParam*>( param );
		if( paramRatio )
		{
			paramRatio->setValue( option.getRatio().first, option.getRatio().second );
			return true;
		}
		OFX::ChoiceParam* paramChoice = dynamic_cast<OFX::ChoiceParam*>( param );
		if( paramChoice )
		{
			paramChoice->setValue( option.getInt() );
			return true;
		}
	}
	catch( std::exception& e )
	{
		TUTTLE_LOG_WARNING( "Can't set option " << libAVOptionName << " to " << value << ": " << e.what() );
		return false;
	}
}
예제 #8
0
/* set up and run a processor */
void
AnaglyphPlugin::setupAndProcess(AnaglyphBase &processor, const OFX::RenderArguments &args)
{
    // get a dst image
    std::auto_ptr<OFX::Image> dst(dstClip_->fetchImage(args.time));
    if (!dst.get()) {
        OFX::throwSuiteStatusException(kOfxStatFailed);
    }
    if (dst->getRenderScale().x != args.renderScale.x ||
        dst->getRenderScale().y != args.renderScale.y ||
        dst->getField() != args.fieldToRender) {
        setPersistentMessage(OFX::Message::eMessageError, "", "OFX Host gave image with wrong scale or field properties");
        OFX::throwSuiteStatusException(kOfxStatFailed);
    }
    OFX::BitDepthEnum dstBitDepth       = dst->getPixelDepth();
    OFX::PixelComponentEnum dstComponents  = dst->getPixelComponents();

    // fetch main input image
    std::auto_ptr<OFX::Image> srcLeft(srcClip_->fetchStereoscopicImage(args.time,0));
    if (srcLeft.get()) {
        if (srcLeft->getRenderScale().x != args.renderScale.x ||
            srcLeft->getRenderScale().y != args.renderScale.y ||
            srcLeft->getField() != args.fieldToRender) {
            setPersistentMessage(OFX::Message::eMessageError, "", "OFX Host gave image with wrong scale or field properties");
            OFX::throwSuiteStatusException(kOfxStatFailed);
        }
    }
    std::auto_ptr<OFX::Image> srcRight(srcClip_->fetchStereoscopicImage(args.time,1));
    if (srcRight.get()) {
        if (srcRight->getRenderScale().x != args.renderScale.x ||
            srcRight->getRenderScale().y != args.renderScale.y ||
            srcRight->getField() != args.fieldToRender) {
            setPersistentMessage(OFX::Message::eMessageError, "", "OFX Host gave image with wrong scale or field properties");
            OFX::throwSuiteStatusException(kOfxStatFailed);
        }
    }

    // make sure bit depths are sane
    if (srcLeft.get()) {
        OFX::BitDepthEnum    srcBitDepth      = srcLeft->getPixelDepth();
        OFX::PixelComponentEnum srcComponents = srcLeft->getPixelComponents();

        // see if they have the same depths and bytes and all
        if (srcBitDepth != dstBitDepth || srcComponents != dstComponents)
            OFX::throwSuiteStatusException(kOfxStatErrImageFormat);
    }
    if (srcRight.get()) {
        OFX::BitDepthEnum    srcBitDepth      = srcRight->getPixelDepth();
        OFX::PixelComponentEnum srcComponents = srcRight->getPixelComponents();

        // see if they have the same depths and bytes and all
        if (srcBitDepth != dstBitDepth || srcComponents != dstComponents)
            OFX::throwSuiteStatusException(kOfxStatErrImageFormat);
    }

    double amtcolour = amtcolour_->getValueAtTime(args.time);
    bool swap = swap_->getValueAtTime(args.time);
    int offset = offset_->getValueAtTime(args.time);

    // set the images
    processor.setDstImg(dst.get());
    processor.setSrcLeftImg(srcLeft.get());
    processor.setSrcRightImg(srcRight.get());

    // set the render window
    processor.setRenderWindow(args.renderWindow);

    // set the parameters
    processor.setAmtColour(amtcolour);
    processor.setSwap(swap);
    processor.setOffset(offset);

    // Call the base class process member, this will call the derived templated process code
    processor.process();
}
예제 #9
0
void WriteOIIOPlugin::encode(const std::string& filename, OfxTime time, const float *pixelData, const OfxRectI& bounds, OFX::PixelComponentEnum pixelComponents, int rowBytes)
{
    if (pixelComponents != OFX::ePixelComponentRGBA && pixelComponents != OFX::ePixelComponentRGB && pixelComponents != OFX::ePixelComponentAlpha) {
        setPersistentMessage(OFX::Message::eMessageError, "", "OIIO: can only write RGBA, RGB or Alpha components images");
        OFX::throwSuiteStatusException(kOfxStatErrFormat);
    }

    int numChannels;
    switch(pixelComponents)
    {
        case OFX::ePixelComponentRGBA:
            numChannels = 4;
            break;
        case OFX::ePixelComponentRGB:
            numChannels = 3;
            break;
        case OFX::ePixelComponentAlpha:
            numChannels = 1;
            break;
        default:
            OFX::throwSuiteStatusException(kOfxStatErrFormat);
    }

    std::auto_ptr<ImageOutput> output(ImageOutput::create(filename));
    if (!output.get()) {
        // output is NULL
        setPersistentMessage(OFX::Message::eMessageError, "", std::string("Cannot create output file ")+filename);
        return;
    }
    
	OpenImageIO::TypeDesc oiioBitDepth;
	//size_t sizeOfChannel = 0;
	int    bitsPerSample  = 0;

	int finalBitDepth_i;
    _bitDepth->getValue(finalBitDepth_i);
    ETuttlePluginBitDepth finalBitDepth = getDefaultBitDepth(filename,(ETuttlePluginBitDepth)finalBitDepth_i);

	switch (finalBitDepth) {
		case eTuttlePluginBitDepthAuto:
            OFX::throwSuiteStatusException(kOfxStatErrUnknown);
		case eTuttlePluginBitDepth8:
			oiioBitDepth = TypeDesc::UINT8;
			bitsPerSample = 8;
			//sizeOfChannel = 1;
			break;
		case eTuttlePluginBitDepth10:
			oiioBitDepth = TypeDesc::UINT16;
			bitsPerSample = 10;
			//sizeOfChannel = 2;
			break;
		case eTuttlePluginBitDepth12:
			oiioBitDepth = TypeDesc::UINT16;
			bitsPerSample = 12;
			//sizeOfChannel = 2;
			break;
		case eTuttlePluginBitDepth16:
			oiioBitDepth = TypeDesc::UINT16;
			bitsPerSample = 16;
			//sizeOfChannel = 2;
			break;
		case eTuttlePluginBitDepth16f:
			oiioBitDepth = TypeDesc::HALF;
			bitsPerSample = 16;
			//sizeOfChannel = 2;
			break;
		case eTuttlePluginBitDepth32:
			oiioBitDepth = TypeDesc::UINT32;
			bitsPerSample = 32;
			//sizeOfChannel = 4;
			break;
		case eTuttlePluginBitDepth32f:
			oiioBitDepth = TypeDesc::FLOAT;
			bitsPerSample = 32;
			//sizeOfChannel = 4;
			break;
		case eTuttlePluginBitDepth64:
			oiioBitDepth = TypeDesc::UINT64;
			bitsPerSample = 64;
			//sizeOfChannel = 8;
			break;
		case eTuttlePluginBitDepth64f:
			oiioBitDepth = TypeDesc::DOUBLE;
			bitsPerSample = 64;
			//sizeOfChannel = 8;
			break;
	}
    ImageSpec spec (bounds.x2 - bounds.x1, bounds.y2 - bounds.y1, numChannels, oiioBitDepth);


    bool premultiply;
    _premult->getValue(premultiply);
    int quality;
    _quality->getValue(quality);
    int orientation;
    _orientation->getValue(orientation);
    int compression_i;
    _compression->getValue(compression_i);
    std::string compression;
    
    switch ((EParamCompression)compression_i) {
        case eParamCompressionAuto:
            break;
        case eParamCompressionNone: // EXR, TIFF, IFF
            compression = "none";
            break;
        case eParamCompressionZip: // EXR, TIFF, Zfile
            compression = "zip";
            break;
        case eParamCompressionZips: // EXR
            compression = "zips";
            break;
        case eParamCompressionRle: // DPX, IFF, EXR, TGA, RLA
            compression = "rle";
        case eParamCompressionPiz: // EXR
            compression = "piz";
            break;
        case eParamCompressionPxr24: // EXR
            compression = "pxr24";
            break;
        case eParamCompressionB44: // EXR
            compression = "b44";
            break;
        case eParamCompressionB44a: // EXR
            compression = "b44a";
            break;
        case eParamCompressionLZW: // TIFF
            compression = "lzw";
            break;
        case eParamCompressionCCITTRLE: // TIFF
            compression = "ccittrle";
            break;
        case eParamCompressionPACKBITS: // TIFF
            compression = "packbits";
            break;
    }

	spec.attribute("oiio:BitsPerSample", bitsPerSample);
	spec.attribute("oiio:UnassociatedAlpha", premultiply);
#ifdef OFX_IO_USING_OCIO
    std::string ocioColorspace = _ocio->getOutputColorspace(time);
    float gamma = 0.;
    std::string colorSpaceStr;
    if (ocioColorspace == "Gamma1.8") {
        // Gamma1.8 in nuke-default
        colorSpaceStr = "GammaCorrected";
        gamma = 1.8;
    } else if (ocioColorspace == "Gamma2.2" || ocioColorspace == "vd8" || ocioColorspace == "vd10" || ocioColorspace == "vd16") {
        // Gamma2.2 in nuke-default
        // vd8, vd10, vd16 in spi-anim and spi-vfx
        colorSpaceStr = "GammaCorrected";
        gamma = 2.2;
    } else if (ocioColorspace == "sRGB" || ocioColorspace == "rrt_srgb" || ocioColorspace == "srgb8") {
        // sRGB in nuke-default
        // rrt_srgb in aces
        // srgb8 in spi-vfx
        colorSpaceStr = "sRGB";
    } else if (ocioColorspace == "Rec709" || ocioColorspace == "rrt_rec709" || ocioColorspace == "hd10") {
        // Rec709 in nuke-default
        // rrt_rec709 in aces
        // hd10 in spi-anim and spi-vfx
        colorSpaceStr = "Rec709";
    } else if(ocioColorspace == "KodakLog" || ocioColorspace == "Cineon" || ocioColorspace == "lg10") {
        // Cineon in nuke-default
        // lg10 in spi-vfx
        colorSpaceStr = "KodakLog";
    } else if(ocioColorspace == "Linear" || ocioColorspace == "linear" || ocioColorspace == "aces" || ocioColorspace == "lnf" || ocioColorspace == "ln16") {
        // linear in nuke-default
        // aces in aces
        // lnf, ln16 in spi-anim and spi-vfx
        colorSpaceStr = "Linear";
    } else if(ocioColorspace == "raw" || ocioColorspace == "ncf") {
        // raw in nuke-default
        // raw in aces
        // ncf in spi-anim and spi-vfx
        // leave empty
    } else {
        //unknown color-space, don't do anything
    }
    if (!colorSpaceStr.empty()) {
        spec.attribute("oiio:ColorSpace", colorSpaceStr);
    }
    if (gamma != 0.) {
        spec.attribute("oiio:Gamma", gamma);
    }
#endif
	spec.attribute("CompressionQuality", quality);
	spec.attribute("Orientation", orientation + 1);
    if (!compression.empty()) { // some formats have a good value for the default compression
        spec.attribute("compression", compression);
    }

    // by default, the channel names are R, G, B, A, which is OK except for Alpha images
    if (pixelComponents == OFX::ePixelComponentAlpha) {
        spec.channelnames.clear();
        spec.channelnames.push_back ("A");
        spec.alpha_channel = 0;
    }
    bool supportsRectangles = output->supports("rectangles");
    
    if (supportsRectangles) {
        spec.x = bounds.x1;
        spec.y = bounds.y1;
        spec.full_x = bounds.x1;
        spec.full_y = bounds.y1;
    }
    
    if (!output->open(filename, spec)) {
        setPersistentMessage(OFX::Message::eMessageError, "", output->geterror());
        OFX::throwSuiteStatusException(kOfxStatFailed);
    }
    
    if (supportsRectangles) {
        output->write_rectangle(spec.x, //xmin
                                spec.x + spec.width, //xmax
                                spec.y, //ymin
                                spec.y + spec.height, //ymax
                                0, //zmin
                                1, //zmax
                                TypeDesc::FLOAT, //datatype
                                (char*)pixelData + (spec.height - 1) * rowBytes, //invert y
                                AutoStride, //xstride
                                -rowBytes, //ystride
                                AutoStride //zstride
                                );
    } else {
        output->write_image(TypeDesc::FLOAT,
                            (char*)pixelData + (spec.height - 1) * rowBytes, //invert y
                            AutoStride, //xstride
                            -rowBytes, //ystride
                            AutoStride //zstride
                            );
    }
    
    output->close();
}