void MaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler /*sampler*/)
{
	const float xy[2] = {
	    (x * this->m_maskWidthInv)  + this->m_mask_px_ofs[0],
	    (y * this->m_maskHeightInv) + this->m_mask_px_ofs[1]};

	if (this->m_rasterMaskHandleTot == 1) {
		if (this->m_rasterMaskHandles[0]) {
			output[0] = BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[0], xy);
		}
		else {
			output[0] = 0.0f;
		}
	}
	else {
		/* incase loop below fails */
		output[0] = 0.0f;

		for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) {
			if (this->m_rasterMaskHandles[i]) {
				output[0] += BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[i], xy);
			}
		}

		/* until we get better falloff */
		output[0] /= this->m_rasterMaskHandleTot;
	}
}
Esempio n. 2
0
static void mask_rasterize_func(TaskPool *pool, void *taskdata, int UNUSED(threadid))
{
	ThreadedMaskRasterizeState *state = (ThreadedMaskRasterizeState *) BLI_task_pool_userdata(pool);
	ThreadedMaskRasterizeData *data = (ThreadedMaskRasterizeData *) taskdata;
	int scanline;
	const float x_inv = 1.0f / (float)state->width;
	const float y_inv = 1.0f / (float)state->height;
	const float x_px_ofs = x_inv * 0.5f;
	const float y_px_ofs = y_inv * 0.5f;

	for (scanline = 0; scanline < data->num_scanlines; scanline++) {
		float xy[2];
		int x, y = data->start_scanline + scanline;

		xy[1] = ((float)y * y_inv) + y_px_ofs;

		for (x = 0; x < state->width; x++) {
			int index = y * state->width + x;

			xy[0] = ((float)x * x_inv) + x_px_ofs;

			state->buffer[index] = BKE_maskrasterize_handle_sample(state->handle, xy);
		}
	}
}
Esempio n. 3
0
/**
 * \brief Rasterize a buffer from a single mask
 *
 * We could get some speedup by inlining #BKE_maskrasterize_handle_sample
 * and calculating each layer then blending buffers, but this function is only
 * used by the sequencer - so better have the caller thread.
 *
 * Since #BKE_maskrasterize_handle_sample is used threaded elsewhere,
 * we can simply use openmp here for some speedup.
 */
void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
                              const unsigned int width, const unsigned int height,
                              float *buffer)
{
#ifdef _MSC_VER
	int y;  /* msvc requires signed for some reason */

	/* ignore sign mismatch */
#  pragma warning(push)
#  pragma warning(disable:4018)
#else
	unsigned int y;
#endif

#pragma omp parallel for private(y)
	for (y = 0; y < height; y++) {
		unsigned int i = y * width;
		unsigned int x;
		float xy[2];
		xy[1] = (float)y / (float)height;
		for (x = 0; x < width; x++, i++) {
			xy[0] = (float)x / (float)width;

			buffer[i] = BKE_maskrasterize_handle_sample(mr_handle, xy);
		}
	}

#ifdef _MSC_VER
#  pragma warning(pop)
#endif

}
Esempio n. 4
0
static void mask_rasterize_func(TaskPool *pool, void *taskdata, int UNUSED(threadid))
{
	ThreadedMaskRasterizeState *state = (ThreadedMaskRasterizeState *) BLI_task_pool_userdata(pool);
	ThreadedMaskRasterizeData *data = (ThreadedMaskRasterizeData *) taskdata;
	int scanline;

	for (scanline = 0; scanline < data->num_scanlines; scanline++) {
		int x, y = data->start_scanline + scanline;
		for (x = 0; x < state->width; x++) {
			int index = y * state->width + x;
			float xy[2];

			xy[0] = (float) x / state->width;
			xy[1] = (float) y / state->height;

			state->buffer[index] = BKE_maskrasterize_handle_sample(state->handle, xy);
		}
	}
}