initiate plugins branch
[wmaker-crm.git] / plugins / libwmfun / bilinear.c
blob3d9632d72d367cbfbe6d1e9e58b1aa98c82cc0e9
1 /*
2 * libwmfun - WindowMaker texture function library
3 * Copyright (C) 1999 Tobias Gloth
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
22 * $Id$
24 * $Log$
25 * Revision 1.1 2000/12/03 18:58:41 id
26 * initiate plugins branch
28 * Revision 1.1.1.1 1999/02/21 17:16:47 gloth
29 * initial revision
33 #include "generic.h"
35 RImage *bilinear (int argc, char **argv, int width, int height,
36 int relief) {
38 int color[4][3];
39 RImage *image;
40 unsigned char *cptr;
41 int i, j, k;
43 argc--; argv++;
45 if (!start_image ("bilinear", argc, 4, 5, width, height, &image)) {
46 return (RImage *)0;
49 for (i=0; i<4; i++) {
50 if (!parse_color (argv[i], color[i])) {
51 error ("can't parse color: \"%s\"\n", argv[i]);
52 return 0;
56 cptr = image->data;
57 for (i=0; i<height; i++) {
58 int b = 0xff * i / height;
59 int t = 0xff - b;
61 for (j=0; j<width; j++) {
62 int r = 0xff * j / width;
63 int l = 0xff - r;
64 int f[4];
66 f[0] = (l*t) >> 8;
67 f[1] = (r*t) >> 8;
68 f[2] = (l*b) >> 8;
69 f[3] = (r*b) >> 8;
71 for (k=0; k<3; k++) {
72 *cptr++ =
73 ( f[0] * color[0][k] +
74 f[1] * color[1][k] +
75 f[2] * color[2][k] +
76 f[3] * color[3][k] ) >> 8;
79 if (RRGBAFormat==image->format)
80 cptr++;
83 return image;