Esempio n. 1
0
bool
TaskClampSW::run(RunParams&) const
{
	RectInt r = target_rect;
	if (!r.valid())
	{
		VectorInt offset = get_offset();
		RectInt ra = sub_task()->target_rect + r.get_min() + get_offset();
		if (ra.valid())
		{
			etl::set_intersect(ra, ra, r);
			if (ra.valid())
			{
				LockWrite ldst(this);
				if (!ldst) return false;
				LockRead lsrc(sub_task());
				if (!lsrc) return false;

				const synfig::Surface &a = lsrc->get_surface();
				synfig::Surface &c = ldst->get_surface();

				for(int y = ra.miny; y < ra.maxy; ++y)
				{
					const Color *ca = &a[y - r.miny + offset[1]][ra.minx - r.minx + offset[0]];
					Color *cc = &c[y][ra.minx];
					for(int x = ra.minx; x < ra.maxx; ++x, ++ca, ++cc)
						clamp_pixel(*cc, *ca);
				}
			}
		}
	}

	return true;
}
Esempio n. 2
0
bool
TaskBlendSW::run(RunParams & /* params */) const
{
	const synfig::Surface &a =
		SurfaceSW::Handle::cast_dynamic( sub_task_a()->target_surface )->get_surface();
	const synfig::Surface &b =
		SurfaceSW::Handle::cast_dynamic( sub_task_b()->target_surface )->get_surface();
	synfig::Surface &c =
		SurfaceSW::Handle::cast_dynamic( target_surface )->get_surface();

	//debug::DebugSurface::save_to_file(a, "TaskBlendSW__run__a");
	//debug::DebugSurface::save_to_file(b, "TaskBlendSW__run__b");

	RectInt r = get_target_rect();
	if (r.valid())
	{
		RectInt ra = sub_task_a()->get_target_rect() + r.get_min() + offset_a;
		if (ra.valid())
		{
			etl::set_intersect(ra, ra, r);
			if (ra.valid() && &a != &c)
			{
				synfig::Surface::pen p = c.get_pen(ra.minx, ra.maxx);
				const_cast<synfig::Surface*>(&a)->blit_to(
					p,
					ra.minx - r.minx - offset_a[0],
					ra.miny - r.miny - offset_a[1],
					ra.maxx - ra.minx,
					ra.maxy - ra.miny );
			}
		}

		RectInt fill[] = { ra, RectInt::zero(), RectInt::zero(), RectInt::zero() };
		RectInt rb = sub_task_b()->get_target_rect() + r.get_min() + offset_b;
		if (rb.valid())
		{
			etl::set_intersect(rb, rb, r);
			if (rb.valid())
			{
				synfig::Surface::alpha_pen ap(c.get_pen(rb.minx, rb.miny));
				ap.set_blend_method(blend_method);
				ap.set_alpha(amount);
				const_cast<synfig::Surface*>(&b)->blit_to(
					ap,
					rb.minx - r.minx - offset_b[0],
					rb.miny - r.miny - offset_b[1],
					rb.maxx - rb.minx,
					rb.maxy - rb.miny );

				if (ra.valid())
				{
					// mark unfilled regions
					fill[0] = fill[1] = fill[2] = fill[3] = ra;
					fill[0].maxx = fill[2].minx = fill[3].minx = std::max(ra.minx, std::min(ra.maxx, rb.minx));
					fill[1].minx = fill[2].maxx = fill[3].maxx = std::max(ra.minx, std::min(ra.maxx, rb.maxx));
					fill[2].maxy = std::max(ra.miny, std::min(ra.maxy, rb.miny));
					fill[3].miny = std::max(ra.miny, std::min(ra.maxy, rb.maxy));
				}
			}
		}

		if (Color::is_straight(blend_method))
		{
			for(int i = 0; i < 4; ++i)
			{
				if (fill[i].valid())
				{
					synfig::Surface::alpha_pen ap(
						c.get_pen(fill[i].minx, fill[i].miny) );
					ap.set_blend_method(blend_method);
					ap.set_alpha(amount);
					c.fill( Color(0, 0, 0, 0), ap,
							fill[i].maxx - fill[i].minx,
							fill[i].maxy - fill[i].miny );
				}
			}
		}
	}

	//debug::DebugSurface::save_to_file(c, "TaskBlendSW__run__c");

	return true;
}