/* * f-pixbuf-unsharp.c * -- This is adapted from a plug-in for the GIMP 1.0 * http://www.stdout.org/~winston/gimp/unsharp.html * (now out of date) by * * Copyright (C) 1999 Winston Chang * * * * Copyright 2004 Novell, Inc. * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #define ROUND(x) ((int) ((x) + 0.5)) /* ----------------------- gen_lookup_table ----------------------- */ /* generates a lookup table for every possible product of 0-255 and each value in the convolution matrix. The returned array is indexed first by matrix position, then by input multiplicand (?) value. */ static gdouble * gen_lookup_table (gdouble *cmatrix, gint cmatrix_length) { int i, j; gdouble* lookup_table = g_new (gdouble, cmatrix_length * 256); gdouble* lookup_table_p = lookup_table; gdouble* cmatrix_p = cmatrix; for (i=0; i y) { for (row = 0; row < y ; row++) { scale=0; /* find the scale factor */ for (j = 0; j < y ; j++) { /* if the index is in bounds, add it to the scale counter */ if ((j + cmatrix_length/2 - row >= 0) && (j + cmatrix_length/2 - row < cmatrix_length)) scale += cmatrix[j + cmatrix_length/2 - row]; } for (i = 0; i= row - cmatrix_length/2) && (j <= row + cmatrix_length/2)) sum += cur_col[j*bytes + i] * cmatrix[j]; } dest_col[row*bytes + i] = (guchar) ROUND (sum / scale); } } } else { /* for the edge condition, we only use available info and scale to one */ for (row = 0; row < cmatrix_middle; row++) { /* find scale factor */ scale=0; for (j = cmatrix_middle - row; j0; j--) { sum += *(ctable_p + *cur_col_p1); cur_col_p1 += bytes; ctable_p += 256; } cur_col_p++; *(dest_col_p++) = ROUND (sum); } } /* for the edge condition , we only use available info, and scale to one */ for (; row < y; row++) { /* find scale factor */ scale=0; for (j = 0; j< y-row + cmatrix_middle; j++) scale += cmatrix[j]; for (i = 0; i