Exemple #1
0
void colorx_node_t::do_expression( const tbb::blocked_range<int>& range, const Imath::Box2i& area, const render::context_t& context)
{
	std::string color_expr = get_value<std::string>( param( expr_param_name()));
	image_expression_t expr( color_expr, this, color_context);
	RAMEN_ASSERT( expr.isValid());

	expr.setup_variables( this, context);
	image::const_image_view_t src = input_as<image_node_t>()->const_subimage_view( area);
	image::image_view_t dst = subimage_view( area);
	
	SeVec3d& cvar = expr.vec_vars["Cs"].val;
	double& avar = expr.vars["As"].val;
	double *out_avar = expr.get_local_var_ref( "Ao", &avar);

	for( int y = range.begin(); y < range.end(); ++y)
	{
		image::const_image_view_t::x_iterator src_it( src.row_begin( y));
		image::image_view_t::x_iterator dst_it( dst.row_begin( y));

		for( int x = 0, xe = src.width(); x < xe; ++x)
		{
			cvar[0] = boost::gil::get_color( *src_it, boost::gil::red_t());
			cvar[1] = boost::gil::get_color( *src_it, boost::gil::green_t());
			cvar[2] = boost::gil::get_color( *src_it, boost::gil::blue_t());
			avar = boost::gil::get_color( *src_it, boost::gil::alpha_t());

			SeVec3d result = expr.evaluate();
			*dst_it++ = image::pixel_t( result[0], result[1], result[2], *out_avar);
			++src_it;
		}
	}
}
Exemple #2
0
  void orientation(const Image<Matrix<T,2,1> >& src, Image<T>& dst)
  {
    if (dst.sizes() != src.sizes())
      dst.resize(src.sizes());

    typedef typename Image<Matrix<T,2,1> >::const_iterator InputIterator;
    typedef typename Image<T>::iterator OutputIterator;

    InputIterator src_it(src.begin());
    InputIterator src_it_end(src.end());
    OutputIterator dst_it(dst.begin());
    for ( ; src_it != src_it_end; ++src_it, ++dst_it)
      *dst_it = std::atan2(src_it->y(), src_it->x());
  }
  void stableNorm(Image<T, D>& dst, const Image<Matrix<T,M,N>, D>& src)
  {
    if (dst.sizes() != src.sizes())
      dst.resize(src.sizes());

    typedef typename Image<Matrix<T,M,N>, D>::const_iterator InputIterator;
    typedef typename Image<T, D>::iterator OutputIterator;

    InputIterator src_it(src.begin());
    InputIterator src_it_end(src.end());
    OutputIterator dst_it(dst.begin());
    for ( ; src_it != src_it_end; ++src_it, ++dst_it)
      *dst_it = src_it->stableNorm();
  }
Exemple #4
0
    void operator()( const tbb::blocked_range<int>& r) const
    {
        for( int j = r.begin(); j < r.end(); ++j)
        {
            image_view_t::x_iterator dst_it( dst_.row_begin( j));

            Imath::V2f p ( 0, j * yscale_);
            float xinc( src_.width() / dst_.width());

            for( int i = 0; i < dst_.width(); ++i)
            {
                *dst_it++ = s_( p);
                p.x += xinc;
            }
        }
    }
Exemple #5
0
void copy_bitmaps(Image* dst, const Image* src, gfx::Clip area)
{
  if (!area.clip(dst->width(), dst->height(), src->width(), src->height()))
    return;

  // Copy process
  ImageConstIterator<BitmapTraits> src_it(src, area.srcBounds(), area.src.x, area.src.y);
  ImageIterator<BitmapTraits> dst_it(dst, area.dstBounds(), area.dst.x, area.dst.y);

  int end_x = area.dst.x+area.size.w;

  for (int end_y=area.dst.y+area.size.h;
       area.dst.y<end_y;
       ++area.dst.y, ++area.src.y) {
    for (int x=area.dst.x; x<end_x; ++x) {
      *dst_it = *src_it;
      ++src_it;
      ++dst_it;
    }
  }
}
Exemple #6
0
void jpg_reader_t::do_read_image( const image::image_view_t& view, const Imath::Box2i& crop, int subsample) const
{
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;

    cinfo.err = jpeg_std_error( &jerr);
    jpeg_create_decompress( &cinfo);

    adobe::auto_ptr<FILE> fp( fopen( filesystem::file_cstring( path_), "rb"));

    if ( !fp)
    {
		jpeg_destroy_decompress( &cinfo);
		throw exception( "Can't open file");
		return;
    }

    jpeg_stdio_src( &cinfo, fp.get());
    jpeg_read_header( &cinfo, TRUE);
    jpeg_start_decompress( &cinfo);

    if( ( cinfo.output_components != 3) && ( cinfo.output_components != 1))
    {
		jpeg_finish_decompress( &cinfo);
		jpeg_destroy_decompress( &cinfo);
		throw unsupported_image();
    }

    std::size_t stride = cinfo.output_width * cinfo.output_components;
    std::vector<boost::uint8_t> scanline_buffer( stride);

    std::vector<boost::uint8_t>::iterator first_item( scanline_buffer.begin());
    unsigned char *ptr = &(*first_item);

    // skip first lines
    int y = 0;
    for( ; y < crop.min.y; ++y)
        jpeg_read_scanlines( &cinfo, &ptr, 1);

    int yy = 0;

    while( y <= crop.max.y)
    {
        jpeg_read_scanlines( &cinfo, &ptr, 1);

		// process one scanline
		image::image_view_t::x_iterator dst_it( view.row_begin( yy));
		unsigned char *q = ptr + ( crop.min.x * cinfo.output_components);
		unsigned char *q_end = ptr + ( ( crop.max.x + 1) * cinfo.output_components);

		if( cinfo.output_components == 3)
		{
			for( ; dst_it != view.row_end( yy); ++dst_it)
			{
				boost::gil::get_color( *dst_it, boost::gil::red_t())	= q[0] / 255.0f;
				boost::gil::get_color( *dst_it, boost::gil::green_t())	= q[1] / 255.0f;
				boost::gil::get_color( *dst_it, boost::gil::blue_t())	= q[2] / 255.0f;
				boost::gil::get_color( *dst_it, boost::gil::alpha_t())	= 1.0f;
				q += ( cinfo.output_components * subsample);
		
				if( q >= q_end)
					q = ptr + ( crop.max.x * cinfo.output_components);
			}
		}
		else
		{
			for( ; dst_it != view.row_end( yy); ++dst_it)
			{
				float x = *q / 255.0f;
				boost::gil::get_color( *dst_it, boost::gil::red_t())	= x;
				boost::gil::get_color( *dst_it, boost::gil::green_t())	= x;
				boost::gil::get_color( *dst_it, boost::gil::blue_t())	= x;
				boost::gil::get_color( *dst_it, boost::gil::alpha_t())	= 1.0f;
				q += ( cinfo.output_components * subsample);
		
				if( q >= q_end)
					q = ptr + ( crop.max.x * cinfo.output_components);
			}
		}

		++yy;

		// skip subsampled scanlines
		for( int s = 0; s < subsample-1; ++s)
		{
           if( cinfo.output_scanline < cinfo.output_height)
                jpeg_read_scanlines( &cinfo, &ptr, 1);

            ++y;
		}

		++y;
	}

	repeat_scanline_until_end( view, yy - 1);

    // skip remaining scanlines
    for( ; cinfo.output_scanline < cinfo.output_height; ++y)
        jpeg_read_scanlines( &cinfo, &ptr, 1);

    jpeg_finish_decompress( &cinfo);
    jpeg_destroy_decompress( &cinfo);
}
Exemple #7
0
    void operator()( const tbb::blocked_range<int>& r) const
    {
        for( int j = r.begin(); j < r.end(); ++j)
        {
            image::const_image_view_t::x_iterator top_it( src_.row_begin( std::max( j - 1, 0)));
            image::const_image_view_t::x_iterator center_it( src_.row_begin( j));
            image::const_image_view_t::x_iterator bottom_it( src_.row_begin( std::min( j + 1, (int) src_.height() - 1)));
            image::image_view_t::x_iterator dst_it( dst_.row_begin( j));

            image::pixel_t acc;

            // first pixel
            for( int k = 0; k < 3; ++k)
            {
                acc[k]  = (*top_it)[k] * k_[0][0];
                acc[k] += (*top_it)[k] * k_[0][1];
                acc[k] += top_it[1][k] * k_[0][2];

                acc[k] += (*center_it)[k] * k_[1][0];
                acc[k] += (*center_it)[k] * k_[1][1];
                acc[k] += center_it[1][k] * k_[1][2];

                acc[k] += (*bottom_it)[k] * k_[2][0];
                acc[k] += (*bottom_it)[k] * k_[2][1];
                acc[k] += bottom_it[1][k] * k_[2][2];

                acc[k] /= inv_sum_weights_;
            }

            *dst_it++ = acc;
            ++top_it;
            ++center_it;
            ++bottom_it;

            // loop
            for( int i = 1, e = src_.width() - 1; i < e; ++i)
            {
                for( int k = 0; k < 3; ++k)
                {
                    acc[k]  = top_it[-1][k] * k_[0][0];
                    acc[k] += ( *top_it)[k] * k_[0][1];
                    acc[k] += top_it[ 1][k] * k_[0][2];

                    acc[k] += center_it[-1][k] * k_[1][0];
                    acc[k] += ( *center_it)[k] * k_[1][1];
                    acc[k] += center_it[ 1][k] * k_[1][2];

                    acc[k] += bottom_it[-1][k] * k_[2][0];
                    acc[k] += ( *bottom_it)[k] * k_[2][1];
                    acc[k] += bottom_it[ 1][k] * k_[2][2];

                    acc[k] /= inv_sum_weights_;
                }

                *dst_it++ = acc;
                ++top_it;
                ++center_it;
                ++bottom_it;
            }

            // last pixel
            for( int k = 0; k < 3; ++k)
            {
                acc[k]  = top_it[-1][k] * k_[0][0];
                acc[k] += ( *top_it)[k] * k_[0][1];
                acc[k] += ( *top_it)[k] * k_[0][2];

                acc[k] += center_it[-1][k] * k_[1][0];
                acc[k] += ( *center_it)[k] * k_[1][1];
                acc[k] += ( *center_it)[k] * k_[1][2];

                acc[k] += bottom_it[-1][k] * k_[2][0];
                acc[k] += ( *bottom_it)[k] * k_[2][1];
                acc[k] += ( *bottom_it)[k] * k_[2][2];

                acc[k] /= inv_sum_weights_;
            }

            *dst_it = acc;
        }
    }