예제 #1
0
void ImageDisplayDriver::imageData( const Box2i &box, const float *data, size_t dataSize )
{
	Box2i tmpBox = box;
	Box2i dataWindow = m_image->getDataWindow();
	tmpBox.extendBy( dataWindow );
	if ( tmpBox != dataWindow )
	{
		throw Exception("The box is outside image data window.");
	}

	int pixelSize = channelNames().size();
	if ( dataSize != (box.max.x - box.min.x + 1) * (box.max.y - box.min.y + 1) * channelNames().size() )
	{
		throw Exception("Invalid dataSize value.");
	}

	int channel, targetX, targetY, sourceWidth, sourceHeight, targetWidth;
	sourceWidth = box.max.x - box.min.x + 1;
	sourceHeight = box.max.y - box.min.y + 1;
	targetWidth = dataWindow.max.x - dataWindow.min.x + 1;
	channel = 0;
	targetX = box.min.x - dataWindow.min.x;
	targetY = box.min.y - dataWindow.min.y;

	for ( vector<string>::const_iterator it = channelNames().begin(); it != channelNames().end(); it++, channel++ )
	{
		vector< float > &target = boost::static_pointer_cast< FloatVectorData >(m_image->variables[ *it ].data)->writable();
		vector< float >::iterator targetIt;
		const float *sourceIt = data+channel;
		targetIt = target.begin()+targetWidth*targetY+targetX;

		for ( int y = 0; y < sourceHeight; y++ )
		{
			for ( int x = 0; x < sourceWidth; x++ )
			{
				*targetIt = *sourceIt;
				sourceIt += pixelSize;
				targetIt++;
			}
			targetIt += targetWidth - sourceWidth;
		}
	}
}
예제 #2
0
void ImageSampler::hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	ComputeNode::hash( output, context, h );

	if( output->parent<Plug>() == colorPlug() )
	{
		std::string channel = channelName( output );
		if( channel.size() )
		{
			V2f pixel = pixelPlug()->getValue();
			Box2i sampleWindow;
			sampleWindow.extendBy( V2i( pixel ) - V2i( 1 ) );
			sampleWindow.extendBy( V2i( pixel ) + V2i( 1 ) );
			Sampler sampler( imagePlug(), channel, sampleWindow );

			sampler.hash( h );
			h.append( pixel );
		}
	}
}
예제 #3
0
void ImageSampler::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
	if( output->parent<Plug>() == colorPlug() )
	{
		float sample = 0;

		std::string channel = channelName( output );
		if( channel.size() )
		{
			V2f pixel = pixelPlug()->getValue();
			Box2i sampleWindow;
			sampleWindow.extendBy( V2i( pixel ) - V2i( 1 ) );
			sampleWindow.extendBy( V2i( pixel ) + V2i( 1 ) );
			Sampler sampler( imagePlug(), channel, sampleWindow, Filter::create( filterPlug()->getValue() ) );
			sample = sampler.sample( pixel.x, pixel.y );
		}

		static_cast<FloatPlug *>( output )->setValue( sample );
		return;
	}

	ComputeNode::compute( output, context );
}
예제 #4
0
void
makeMultiView (const vector <string> &viewNames,
	       const vector <const char *> &inFileNames,
	       const char *outFileName,
	       Compression compression,
	       bool verbose)
{
    Header header;
    Image image;
    FrameBuffer outFb;

    //
    // Find the size of the dataWindow, check files
    //
    
    Box2i d;
    
    
    for (int i = 0; i < viewNames.size(); ++i)
    {
	InputFile in (inFileNames[i]);

	if (verbose)
	{
	    cout << "reading file " << inFileNames[i] << " "
		    "for " << viewNames[i] << " view" << endl;
	}

	if (hasMultiView (in.header()))
	{
	    THROW (IEX_NAMESPACE::NoImplExc,
		   "The image in file " << inFileNames[i] << " is already a "
		   "multi-view image.  Cannot combine multiple multi-view "
		   "images.");
	}

        header = in.header();
	if (i == 0)
        {
             d=header.dataWindow();
	}else{
             d.extendBy(header.dataWindow());
        }
    }
    
    
    image.resize (d);
    
    header.dataWindow()=d;
    
    // blow away channels; we'll rebuild them
    header.channels()=ChannelList();
    
    
    //
    // Read the input image files
    //

    for (int i = 0; i < viewNames.size(); ++i)
    {
	InputFile in (inFileNames[i]);

	if (verbose)
	{
	    cout << "reading file " << inFileNames[i] << " "
		    "for " << viewNames[i] << " view" << endl;
	}

	FrameBuffer inFb;

	for (ChannelList::ConstIterator j = in.header().channels().begin();
	     j != in.header().channels().end();
	     ++j)
	{
	    const Channel &inChannel = j.channel();
	    string inChanName = j.name();
	    string outChanName = insertViewName (inChanName, viewNames, i);

	    image.addChannel (outChanName, inChannel);
            image.channel(outChanName).black();
            
	    header.channels().insert (outChanName, inChannel);

	    inFb.insert  (inChanName,  image.channel(outChanName).slice());
	    outFb.insert (outChanName, image.channel(outChanName).slice());
	}

	in.setFrameBuffer (inFb);
	in.readPixels (in.header().dataWindow().min.y, in.header().dataWindow().max.y);
    }

    //
    // Write the output image file
    //

    {
	header.compression() = compression;
	addMultiView (header, viewNames);

	OutputFile out (outFileName, header);

	if (verbose)
	    cout << "writing file " << outFileName << endl;

	out.setFrameBuffer (outFb);

	out.writePixels
	    (header.dataWindow().max.y - header.dataWindow().min.y + 1);
    }
}