Esempio n. 1
0
void test_image_basic(const std::string& prefix) {
    typedef typename Img::view_t View;

    // make a 20x20 image
    Img img(typename View::point_t(20,20));
    const View& img_view=view(img);

    // fill it with red
    rgb8_pixel_t red8(255,0,0), green8(0,255,0), blue8(0,0,255), white8(255,255,255);
    typename View::value_type red,green,blue,white;
    color_convert(red8,red);
    default_color_converter()(red8,red);
    red=color_convert_deref_fn<rgb8_ref_t,typename Img::view_t::value_type>()(red8);

    color_convert(green8,green);
    color_convert(blue8,blue);
    color_convert(white8,white);
    fill(img_view.begin(),img_view.end(),red);

    color_convert(red8,img_view[0]);

    // pointer to first pixel of second row
    typename View::reference rt=img_view.at(0,0)[img_view.width()];
    typename View::x_iterator ptr=&rt; ignore_unused_variable_warning(ptr);
    typename View::reference rt2=*(img_view.at(0,0)+img_view.width());
    typename View::x_iterator ptr2=&rt2; ignore_unused_variable_warning(ptr2);
    assert(ptr==ptr2);
    assert(img_view.x_at(0,0)+10==10+img_view.x_at(0,0));

    // draw a blue line along the diagonal
    typename View::xy_locator loc=img_view.xy_at(0,img_view.height()-1);
    for (int y=0; y<img_view.height(); ++y) {
        *loc=blue;
        ++loc.x();
        loc.y()--;
    }

    // draw a green dotted line along the main diagonal with step of 3
    loc=img_view.xy_at(img_view.width()-1,img_view.height()-1);
    while (loc.x()>=img_view.x_at(0,0)) {
        *loc=green;
        loc-=typename View::point_t(3,3);
    }

    // Clone and make every red pixel white
    Img imgWhite(img);
    for (typename View::iterator it=view(imgWhite).end(); (it-1)!=view(imgWhite).begin(); --it) {
        if (*(it-1)==red)
            *(it-1)=white;
    }
    // make sure the const iterators can be constructed from non-const ones.
    typename Img::const_iterator tst=imgWhite.begin();

    check_image(img_view,prefix+"red_x.jpg");
    check_image(view(imgWhite),prefix+"white_x.jpg");
}
Esempio n. 2
0
GIL_FORCEINLINE F transform_pixels_locator(const View& dst, const F& fun)
{
    typename View::xy_locator dloc = dst.xy_at(0, 0);
    for(std::ptrdiff_t y = 0; y < dst.height(); ++y)
    {
        for(std::ptrdiff_t x = 0; x < dst.width(); ++x, ++dloc.x())
        {
            fun(dloc);
        }
        dloc.x() -= dst.width();
        ++dloc.y();
    }
    return fun;
}
Esempio n. 3
0
GIL_FORCEINLINE F transform_pixels_locator(const View& dst, const Rect<std::ptrdiff_t>& dstRod,
                                           const Rect<std::ptrdiff_t>& renderWin, F& fun)
{
    const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1;
    typename View::xy_locator dloc = dst.xy_at(renderWin.x1 - dstRod.x1, renderWin.y1 - dstRod.y1);
    for(std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y)
    {
        for(std::ptrdiff_t x = renderWin.x1; x < renderWin.x2; ++x, ++dloc.x())
        {
            fun(dloc);
        }
        dloc.x() -= renderWidth;
        ++dloc.y();
    }
    return fun;
}
Esempio n. 4
0
GIL_FORCEINLINE F transform_pixels_locator(const View& src, const Rect<std::ptrdiff_t>& srcRod, const ViewDst& dst,
                                           const Rect<std::ptrdiff_t>& dstRod, const Rect<std::ptrdiff_t>& renderWin, F& fun)
{
    const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1;
    typename View::xy_locator sloc = src.xy_at(renderWin.x1 - srcRod.x1, renderWin.y1 - srcRod.y1);
    for(std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y)
    {
        typename ViewDst::x_iterator dstIt = dst.x_at(renderWin.x1 - dstRod.x1, y - dstRod.y1);
        for(std::ptrdiff_t x = renderWin.x1; x < renderWin.x2; ++x, ++sloc.x(), ++dstIt)
        {
            *dstIt = fun(sloc);
        }
        sloc.x() -= renderWidth;
        ++sloc.y();
    }
    return fun;
}
Esempio n. 5
0
GIL_FORCEINLINE
F transform_pixels_locator_progress( const View& dst, const OfxRectI& dstRod,
									 const OfxRectI& renderWin, const F& fun, IProgress& p )
{
	const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1;
	typename View::xy_locator dloc = dst.xy_at( renderWin.x1-dstRod.x1, renderWin.y1-dstRod.y1 );
	for( std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y )
	{
		for( std::ptrdiff_t x = renderWin.x1;
		     x < renderWin.x2;
		     ++x, ++dloc.x() )
		{
			fun( dloc );
		}
		dloc.x() -= renderWidth; ++dloc.y();
		if( p.progressForward( renderWidth ) )
			return fun;
	}
	return fun;
}
Esempio n. 6
0
GIL_FORCEINLINE
F transform_pixels_locator_progress( const View& src, const OfxRectI& srcRod,
									 const ViewDst& dst, const OfxRectI& dstRod,
									 const OfxRectI& renderWin, const F& fun, IProgress& p )
{
	const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1;
	typename View::xy_locator sloc = src.xy_at( renderWin.x1-srcRod.x1, renderWin.y1-srcRod.y1 );
	for( std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y )
	{
		typename ViewDst::x_iterator dstIt = dst.x_at( renderWin.x1-dstRod.x1, y-dstRod.y1 );
		for( std::ptrdiff_t x = renderWin.x1;
		     x < renderWin.x2;
		     ++x, ++sloc.x(), ++dstIt )
		{
			*dstIt = fun( sloc );
		}
		sloc.x() -= renderWidth; ++sloc.y();
		if( p.progressForward( renderWidth ) )
			return fun;
	}
	return fun;
}