Esempio n. 1
0
void cineon_writer_t::write_pixels( std::ofstream& out, const image::const_image_view_t& view) const
{
    std::vector<boost::uint32_t> buffer( view.width());

    for( int y = 0; y < view.height(); ++y)
    {
		image::const_image_view_t::x_iterator src_it( view.row_begin( y));
	
		for( int x = 0; x < view.width(); ++x)
		{
			boost::uint32_t pix = 0;
	
			float r = boost::gil::get_color( *src_it, boost::gil::red_t());
			float g = boost::gil::get_color( *src_it, boost::gil::green_t());
			float b = boost::gil::get_color( *src_it, boost::gil::blue_t());
	
			boost::uint32_t ri = adobe::clamp( r, 0.0f, 1.0f) * 1023;
			boost::uint32_t gi = adobe::clamp( g, 0.0f, 1.0f) * 1023;
			boost::uint32_t bi = adobe::clamp( b, 0.0f, 1.0f) * 1023;
			pix = ( ri << 22) | ( gi << 12) | ( bi << 2);
	
			buffer[x] = IECore::asBigEndian( pix);
			++src_it;
		}
	
		// write vector
		out.write( reinterpret_cast<char *>( &buffer[0]), view.width() * sizeof( boost::uint32_t));
		
		if ( out.fail())
			throw exception( "error while writting image");
    }
}
Esempio n. 2
0
void tga_writer_t::do_write_image( const boost::filesystem::path& p,
				const image::const_image_view_t& view,
				const adobe::dictionary_t& params) const
{
    int channels    = adobe::get_value( params, adobe::name_t( "channels")).cast<int>();
    int compress    = adobe::get_value( params, adobe::name_t( "compress")).cast<int>();
    
    std::auto_ptr<OIIO::ImageOutput> out( OIIO::ImageOutput::create( filesystem::file_string( p)));

    if( !out.get())
		throw exception( "Write TGA: Can't open output file");

    if( channels)
		channels = 3;
    else
		channels = 4;

    OIIO::ImageSpec spec( view.width(), view.height(), channels, OIIO::TypeDesc::UINT8);
	add_common_attributes( spec);

	switch( compress)
	{
		case none_compression:
		break;
		
		case rle_compression:
			spec.attribute( "compression", "rle");
		break;
		
		default:
			throw unsupported_image( "unsupported compression");
	}

    if( !out->open( filesystem::file_string( p), spec))
		throw exception( "Can't open output file");

    std::vector<image::pixel_t> scanline( view.width());

    for( int y = 0; y < view.height(); ++y)
    {
		std::copy( view.row_begin( y), view.row_end( y), scanline.begin());
		clamp( scanline.begin(), scanline.end());
	
		if( !out->write_scanline( y, 0, OIIO::TypeDesc::FLOAT, (void *) &( *scanline.begin()), sizeof( image::pixel_t)))
			throw exception( "Write image: Can't write pixels");
    }

    if( !out->close())
		throw exception( "Write image: Can't close file");
}
Esempio n. 3
0
void png_writer_t::do_write_image( const boost::filesystem::path& p,
				const image::const_image_view_t& view,
				const adobe::dictionary_t& params) const
{
    int channels = adobe::get_value( params, adobe::name_t( "channels")).cast<int>();

    std::auto_ptr<OpenImageIO::ImageOutput> out( OpenImageIO::ImageOutput::create( p.external_file_string()));

    if( !out.get())
	throw std::runtime_error( "Write PNG: Can't open output file");

    if( channels)
	channels = 3;
    else
	channels = 4;

    OpenImageIO::ImageSpec spec( view.width(), view.height(), channels, TypeDesc::UINT8);
    spec.quant_dither = 0.0f;

    if( !out->open( p.external_file_string(), spec))
	throw( std::runtime_error( "Can't open output file"));
    
    std::vector<image::pixel_t> scanline( view.width());

    for( int y = 0; y < view.height(); ++y)
    {
	std::copy( view.row_begin( y), view.row_end( y), scanline.begin());
	apply_gamma( 1.0f / 2.2f, scanline.begin(), scanline.end());
	clamp( scanline.begin(), scanline.end());

	if( !out->write_scanline( y, 0, TypeDesc::FLOAT, (void *) &( *scanline.begin()), sizeof( image::pixel_t)))
	    throw( std::runtime_error( "Write image: Can't write pixels"));
    }

    if( !out->close())
	throw std::runtime_error( "Write image: Can't close file");
}
Esempio n. 4
0
void png_writer_t::do_write_image( const boost::filesystem::path& p,
									const image::const_image_view_t& view,
                                    const core::dictionary_t& params) const
{
    int channels = core::get<int>( params, core::name_t( "channels"));

    std::auto_ptr<OIIO::ImageOutput> out( OIIO::ImageOutput::create( filesystem::file_string( p)));

    if( !out.get())
		throw exception( "Write PNG: Can't open output file");

    if( channels)
		channels = 3;
    else
		channels = 4;

    OIIO::ImageSpec spec( view.width(), view.height(), channels, OIIO::TypeDesc::UINT8);
	add_common_attributes( spec);

    if( !out->open( filesystem::file_string( p), spec))
		throw exception( "Can't open output file");
    
    std::vector<image::pixel_t> scanline( view.width());

    for( int y = 0; y < view.height(); ++y)
    {
		std::copy( view.row_begin( y), view.row_end( y), scanline.begin());
		clamp( scanline.begin(), scanline.end());

		if( !out->write_scanline( y, 0, OIIO::TypeDesc::FLOAT, (void *) &( *scanline.begin()), sizeof( image::pixel_t)))
		    throw exception( "Write image: Can't write pixels");
    }

    if( !out->close())
		throw exception( "Write image: Can't close file");
}