/* * Copyright 2011, 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. */ #include "camera.h" #include "device.h" #include "filter.h" #include "scene.h" #include "util_algorithm.h" #include "util_debug.h" #include "util_math.h" CCL_NAMESPACE_BEGIN Filter::Filter() { filter_type = FILTER_BOX; filter_width = 1.0f; need_update = true; } Filter::~Filter() { } static float filter_func_box(float v, float width) { return (float)1; } static float filter_func_gaussian(float v, float width) { v *= (float)2/width; return (float)expf((float)-2*v*v); } static vector filter_table(FilterType type, float width) { const int filter_table_size = 256; vector filter_table_cdf(filter_table_size+1); vector filter_table(filter_table_size+1); float (*filter_func)(float, float) = NULL; int i, half_size = filter_table_size/2; switch(type) { case FILTER_BOX: filter_func = filter_func_box; break; case FILTER_GAUSSIAN: filter_func = filter_func_gaussian; break; default: assert(0); } /* compute cumulative distribution function */ filter_table_cdf[0] = 0.0f; for(i=0; i table = filter_table(filter_type, filter_width); dscene->filter_table.copy(&table[0], table.size()); device->tex_alloc("__filter_table", dscene->filter_table, true); need_update = false; } void Filter::device_free(Device *device, DeviceScene *dscene) { device->tex_free(dscene->filter_table); dscene->filter_table.clear(); } CCL_NAMESPACE_END