void *AntiAliasOperation::initializeTileData(rcti *rect)
{
	if (this->m_buffer) { return this->m_buffer; }
	lockMutex();
	if (this->m_buffer == NULL) {
		MemoryBuffer *tile = (MemoryBuffer *)this->m_valueReader->initializeTileData(rect);
		int size = tile->getHeight() * tile->getWidth();
		float *input = tile->getBuffer();
		char *valuebuffer = (char *)MEM_mallocN(sizeof(char) * size, __func__);
		for (int i = 0; i < size; i++) {
			float in = input[i * COM_NUMBER_OF_CHANNELS];
			valuebuffer[i] = FTOCHAR(in);
		}
		antialias_tagbuf(tile->getWidth(), tile->getHeight(), valuebuffer);
		this->m_buffer = valuebuffer;
	}
	unlockMutex();
	return this->m_buffer;
}
Esempio n. 2
0
/* stackbuf should be zeroed */
static void do_idmask(CompBuf *stackbuf, CompBuf *cbuf, float idnr)
{
	float *rect;
	int x;
	char *abuf= MEM_mapallocN(cbuf->x*cbuf->y, "anti ali buf");
	
	rect= cbuf->rect;
	for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
		if(rect[x]==idnr)
			abuf[x]= 255;
	
	antialias_tagbuf(cbuf->x, cbuf->y, abuf);
	
	rect= stackbuf->rect;
	for(x= cbuf->x*cbuf->y - 1; x>=0; x--)
		if(abuf[x]>1)
			rect[x]= (1.0f/255.0f)*(float)abuf[x];
	
	MEM_freeN(abuf);
}
static void node_composit_exec_zcombine(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
	RenderData *rd= data;
	CompBuf *cbuf= in[0]->data;
	CompBuf *zbuf;

	/* stack order in: col z col z */
	/* stack order out: col z */
	if (out[0]->hasoutput==0 && out[1]->hasoutput==0) 
		return;
	
	/* no input image; do nothing now */
	if (in[0]->data==NULL) {
		return;
	}
	
	if (out[1]->hasoutput) {
		/* copy or make a buffer for for the first z value, here we write result in */
		if (in[1]->data)
			zbuf= dupalloc_compbuf(in[1]->data);
		else {
			float *zval;
			int tot= cbuf->x*cbuf->y;
			
			zbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1);
			for (zval= zbuf->rect; tot; tot--, zval++)
				*zval= in[1]->vec[0];
		}
		/* lazy coder hack */
		node->custom2= 1;
		out[1]->data= zbuf;
	}
	else {
		node->custom2= 0;
		zbuf= in[1]->data;
	}
	
	if (rd->scemode & R_FULL_SAMPLE) {
		/* make output size of first input image */
		CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs
		
		composit4_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, zbuf, in[1]->vec, in[2]->data, in[2]->vec, 
								  in[3]->data, in[3]->vec, do_zcombine, CB_RGBA, CB_VAL, CB_RGBA, CB_VAL);
		
		out[0]->data= stackbuf;
	}
	else {
		/* make output size of first input image */
		CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */
		CompBuf *mbuf;
		float *fp;
		int x;
		char *aabuf;
		
		
		/* make a mask based on comparison, optionally write zvalue */
		mbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1);
		composit2_pixel_processor(node, mbuf, zbuf, in[1]->vec, in[3]->data, in[3]->vec, do_zcombine_mask, CB_VAL, CB_VAL);
		
		/* convert to char */
		aabuf= MEM_mallocN(cbuf->x*cbuf->y, "aa buf");
		fp= mbuf->rect;
		for (x= cbuf->x*cbuf->y-1; x>=0; x--)
			if (fp[x]==0.0f) aabuf[x]= 0;
			else aabuf[x]= 255;
		
		antialias_tagbuf(cbuf->x, cbuf->y, aabuf);
		
		/* convert to float */
		fp= mbuf->rect;
		for (x= cbuf->x*cbuf->y-1; x>=0; x--)
			if (aabuf[x]>1)
				fp[x]= (1.0f/255.0f)*(float)aabuf[x];
		
		composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, in[2]->data, in[2]->vec, mbuf, NULL, 
								  do_zcombine_add, CB_RGBA, CB_RGBA, CB_VAL);
		/* free */
		free_compbuf(mbuf);
		MEM_freeN(aabuf);
		
		out[0]->data= stackbuf;
	}

}