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;
}
Exemple #2
0
// 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);
}
Exemple #3
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();
}