Change to the linux kernel coding style
[wmaker-crm.git] / plugins / libwmfun / bilinear.c
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.
9 *
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.
14 *
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.
19 */
20
21 /*
22 * $Id$
23 *
24 * $Log$
25 * Revision 1.1 2000/12/03 18:58:41 id
26 * initiate plugins branch
27 *
28 * Revision 1.1.1.1 1999/02/21 17:16:47 gloth
29 * initial revision
30 *
31 */
32
33 #include "generic.h"
34
35 RImage *bilinear(int argc, char **argv, int width, int height, int relief)
36 {
37
38 int color[4][3];
39 RImage *image;
40 unsigned char *cptr;
41 int i, j, k;
42
43 argc--;
44 argv++;
45
46 if (!start_image("bilinear", argc, 4, 5, width, height, &image)) {
47 return (RImage *) 0;
48 }
49
50 for (i = 0; i < 4; i++) {
51 if (!parse_color(argv[i], color[i])) {
52 error("can't parse color: \"%s\"\n", argv[i]);
53 return 0;
54 }
55 }
56
57 cptr = image->data;
58 for (i = 0; i < height; i++) {
59 int b = 0xff * i / height;
60 int t = 0xff - b;
61
62 for (j = 0; j < width; j++) {
63 int r = 0xff * j / width;
64 int l = 0xff - r;
65 int f[4];
66
67 f[0] = (l * t) >> 8;
68 f[1] = (r * t) >> 8;
69 f[2] = (l * b) >> 8;
70 f[3] = (r * b) >> 8;
71
72 for (k = 0; k < 3; k++) {
73 *cptr++ =
74 (f[0] * color[0][k] +
75 f[1] * color[1][k] + f[2] * color[2][k] + f[3] * color[3][k]) >> 8;
76 }
77
78 if (RRGBAFormat == image->format)
79 cptr++;
80 }
81 }
82 return image;
83 }