| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright 2012, Blender Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor: | 
					
						
							|  |  |  |  *		Jeroen Bakker | 
					
						
							|  |  |  |  *		Monique Dewanchand | 
					
						
							|  |  |  |  *		Sergey Sharybin | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "COM_KeyingBlurOperation.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_listbase.h"
 | 
					
						
							|  |  |  | #include "BLI_math.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-15 09:58:52 +00:00
										 |  |  | KeyingBlurOperation::KeyingBlurOperation() : NodeOperation() | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	this->addInputSocket(COM_DT_VALUE); | 
					
						
							|  |  |  | 	this->addOutputSocket(COM_DT_VALUE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 01:22:05 +00:00
										 |  |  | 	this->m_size = 0; | 
					
						
							|  |  |  | 	this->m_axis = BLUR_AXIS_X; | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	this->setComplex(true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-13 12:24:42 +00:00
										 |  |  | void *KeyingBlurOperation::initializeTileData(rcti *rect) | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-07-13 12:24:42 +00:00
										 |  |  | 	void *buffer = getInputOperation(0)->initializeTileData(rect); | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return buffer; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 14:07:24 +00:00
										 |  |  | void KeyingBlurOperation::executePixel(float output[4], int x, int y, void *data) | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-15 09:58:52 +00:00
										 |  |  | 	MemoryBuffer *inputBuffer = (MemoryBuffer *)data; | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:28 +06:00
										 |  |  | 	const int bufferWidth = inputBuffer->getWidth(); | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | 	float *buffer = inputBuffer->getBuffer(); | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:28 +06:00
										 |  |  | 	int count = 0; | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | 	float average = 0.0f; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 01:22:05 +00:00
										 |  |  | 	if (this->m_axis == 0) { | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:28 +06:00
										 |  |  | 		const int start = max(0, x - this->m_size + 1), | 
					
						
							|  |  |  | 		          end = min(bufferWidth, x + this->m_size); | 
					
						
							|  |  |  | 		for (int cx = start; cx < end; ++cx) { | 
					
						
							| 
									
										
										
										
											2015-01-19 18:13:26 +01:00
										 |  |  | 			int bufferIndex = (y * bufferWidth + cx); | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:28 +06:00
										 |  |  | 			average += buffer[bufferIndex]; | 
					
						
							|  |  |  | 			count++; | 
					
						
							| 
									
										
										
										
											2012-06-25 08:21:55 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:28 +06:00
										 |  |  | 		const int start = max(0, y - this->m_size + 1), | 
					
						
							|  |  |  | 		          end = min(inputBuffer->getHeight(), y + this->m_size); | 
					
						
							|  |  |  | 		for (int cy = start; cy < end; ++cy) { | 
					
						
							| 
									
										
										
										
											2015-01-19 18:13:26 +01:00
										 |  |  | 			int bufferIndex = (cy * bufferWidth + x); | 
					
						
							| 
									
										
										
										
											2014-10-01 16:36:28 +06:00
										 |  |  | 			average += buffer[bufferIndex]; | 
					
						
							|  |  |  | 			count++; | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	average /= (float) count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 14:07:24 +00:00
										 |  |  | 	output[0] = average; | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool KeyingBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	rcti newInput; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 01:22:05 +00:00
										 |  |  | 	if (this->m_axis == BLUR_AXIS_X) { | 
					
						
							|  |  |  | 		newInput.xmin = input->xmin - this->m_size; | 
					
						
							| 
									
										
										
										
											2012-06-25 08:21:55 +00:00
										 |  |  | 		newInput.ymin = input->ymin; | 
					
						
							| 
									
										
										
										
											2012-06-26 01:22:05 +00:00
										 |  |  | 		newInput.xmax = input->xmax + this->m_size; | 
					
						
							| 
									
										
										
										
											2012-06-25 08:21:55 +00:00
										 |  |  | 		newInput.ymax = input->ymax; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		newInput.xmin = input->xmin; | 
					
						
							| 
									
										
										
										
											2012-06-26 01:22:05 +00:00
										 |  |  | 		newInput.ymin = input->ymin - this->m_size; | 
					
						
							| 
									
										
										
										
											2012-06-25 08:21:55 +00:00
										 |  |  | 		newInput.xmax = input->xmax; | 
					
						
							| 
									
										
										
										
											2012-06-26 01:22:05 +00:00
										 |  |  | 		newInput.ymax = input->ymax + this->m_size; | 
					
						
							| 
									
										
										
										
											2012-06-25 08:21:55 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-14 12:19:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); | 
					
						
							|  |  |  | } |