Exemplo n.º 1
0
/* only used for image editor curves */
void curvemapping_do_ibuf(CurveMapping *cumap, ImBuf *ibuf)
{
	ImBuf *tmpbuf;
	int pixel;
	float *pix_in;
	float col[3];
	int stride = 4;
	float *pix_out;
	
	if (ibuf == NULL)
		return;
	if (ibuf->rect_float == NULL)
		IMB_float_from_rect(ibuf);
	else if (ibuf->rect == NULL)
		imb_addrectImBuf(ibuf);
	
	if (!ibuf->rect || !ibuf->rect_float)
		return;
	
	/* work on a temp buffer, so can color manage afterwards.
	 * No worse off memory wise than comp nodes */
	tmpbuf = IMB_dupImBuf(ibuf);
	
	curvemapping_premultiply(cumap, 0);
	
	pix_in = ibuf->rect_float;
	pix_out = tmpbuf->rect_float;

	if (ibuf->channels)
		stride = ibuf->channels;
	
	for (pixel = ibuf->x * ibuf->y; pixel > 0; pixel--, pix_in += stride, pix_out += stride) {
		if (stride < 3) {
			col[0] = curvemap_evaluateF(cumap->cm, *pix_in);
			
			pix_out[1] = pix_out[2] = pix_out[3] = pix_out[0] = col[0];
		}
		else {
			curvemapping_evaluate_premulRGBF(cumap, col, pix_in);
			pix_out[0] = col[0];
			pix_out[1] = col[1];
			pix_out[2] = col[2];
			if (stride > 3)
				pix_out[3] = pix_in[3];
			else
				pix_out[3] = 1.f;
		}
	}
	
	IMB_rect_from_float(tmpbuf);
	SWAP(unsigned int *, tmpbuf->rect, ibuf->rect);
	IMB_freeImBuf(tmpbuf);
	
	curvemapping_premultiply(cumap, 1);
}
Exemplo n.º 2
0
/* XXX Group nodes must set use_tree_data to false, since their trees can be shared by multiple nodes.
 * If use_tree_data is true, the ntree->execdata pointer is checked to avoid multiple execution of top-level trees.
 */
void ntreeCompositEndExecTree(bNodeTreeExec *exec, int use_tree_data)
{
	if (exec) {
		bNodeTree *ntree= exec->nodetree;
		bNode *node;
		bNodeStack *ns;
		
		for (node= exec->nodetree->nodes.first; node; node= node->next) {
			bNodeSocket *sock;
			
			for (sock= node->outputs.first; sock; sock= sock->next) {
				ns = node_get_socket_stack(exec->stack, sock);
				if (ns && ns->data) {
					sock->cache= ns->data;
					ns->data= NULL;
				}
			}
			if (node->type==CMP_NODE_CURVE_RGB)
				curvemapping_premultiply(node->storage, 1);
			
			node->need_exec= 0;
		}
	
		ntree_exec_end(exec);
		
		if (use_tree_data) {
			/* XXX clear nodetree backpointer to exec data, same problem as noted in ntreeBeginExecTree */
			ntree->execdata = NULL;
		}
	}
}
Exemplo n.º 3
0
static void curves_apply(struct SequenceModifierData *smd, ImBuf *ibuf, ImBuf *mask)
{
	CurvesModifierData *cmd = (CurvesModifierData *) smd;

	float black[3] = {0.0f, 0.0f, 0.0f};
	float white[3] = {1.0f, 1.0f, 1.0f};

	curvemapping_initialize(&cmd->curve_mapping);

	curvemapping_premultiply(&cmd->curve_mapping, 0);
	curvemapping_set_black_white(&cmd->curve_mapping, black, white);

	modifier_apply_threaded(ibuf, mask, curves_apply_threaded, &cmd->curve_mapping);

	curvemapping_premultiply(&cmd->curve_mapping, 1);
}
Exemplo n.º 4
0
/* XXX Group nodes must set use_tree_data to false, since their trees can be shared by multiple nodes.
 * If use_tree_data is true, the ntree->execdata pointer is checked to avoid multiple execution of top-level trees.
 */
struct bNodeTreeExec *ntreeCompositBeginExecTree(bNodeTree *ntree, int use_tree_data)
{
	bNodeTreeExec *exec;
	bNode *node;
	bNodeSocket *sock;
	
	if (use_tree_data) {
		/* XXX hack: prevent exec data from being generated twice.
		 * this should be handled by the renderer!
		 */
		if (ntree->execdata)
			return ntree->execdata;
	}
	
	/* ensures only a single output node is enabled */
	ntreeSetOutput(ntree);
	
	exec = ntree_exec_begin(ntree);
	
	for (node= exec->nodetree->nodes.first; node; node= node->next) {
		/* initialize needed for groups */
		node->exec= 0;
		
		for (sock= node->outputs.first; sock; sock= sock->next) {
			bNodeStack *ns= node_get_socket_stack(exec->stack, sock);
			if (ns && sock->cache) {
				ns->data= sock->cache;
				sock->cache= NULL;
			}
		}
		/* cannot initialize them while using in threads */
		if (ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) {
			curvemapping_initialize(node->storage);
			if (node->type==CMP_NODE_CURVE_RGB)
				curvemapping_premultiply(node->storage, 0);
		}
	}
	
	if (use_tree_data) {
		/* XXX this should not be necessary, but is still used for cmp/sha/tex nodes,
		 * which only store the ntree pointer. Should be fixed at some point!
		 */
		ntree->execdata = exec;
	}
	
	return exec;
}