added None option to MoveDisplay and ResizeDisplay
[wmaker-crm.git] / plugins / libwmfun / fade.c
blobc416a7afe0d2b85cb7420f5689eaf304c016800a
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.
21 #include "getopt.h"
22 #include <math.h>
23 #include <stdlib.h>
24 #include <time.h>
26 #include "generic.h"
28 RImage *fade (int argc, char **argv, int width, int height, int relief) {
30 int from[3] = { 0x00, 0x00, 0x00 };
31 int to[3] = { 0xff, 0xff, 0xff };
32 int *this, *last;
33 RImage *image;
34 unsigned char *cptr;
35 int i, j;
36 double factor, delta;
38 int c, done, option_index = 0;
40 optind = 1;
41 for (done=0; !done; ) {
42 static struct option long_options[] = {
43 {"from", 1, 0, 'f'},
44 {"to", 1, 0, 't'},
45 {0, 0, 0, 0}
48 c = getopt_long (argc, argv, "f:t:",
49 long_options, &option_index);
50 if (c == -1) {
51 break;
54 switch (c) {
55 case 'f':
56 if (!parse_color (optarg, from)) {
57 error ("invalid color: %s\n", optarg);
58 return 0;
60 break;
61 case 't':
62 if (!parse_color (optarg, to)) {
63 error ("invalid color: %s\n", optarg);
64 return 0;
66 break;
67 default:
68 done = 1;
69 break;
73 argc -= optind;
74 argv += optind;
76 if (!start_image ("fade", argc, 0, 1, width, height, &image)) {
77 return (RImage *)0;
80 this = (int *) malloc (width * sizeof (int));
81 last = (int *) malloc (width * sizeof (int));
82 if (!this || !last) {
83 RReleaseImage (image);
84 free (this);
85 free (last);
86 return (RImage *)0;
89 for (i=0; i<width; i++) {
90 this[i] = 255;
93 factor = pow (0.2, 1.0 / height);
94 delta = (factor < 0.5) ? 2.0 * factor : 2.0 * (1.0 - factor);
96 srand (time (0));
98 cptr = image->data;
99 for (j=0; j<height; j++) {
100 memcpy (last, this, width * sizeof (int));
101 for (i=0; i<width; i++) {
102 int output[3];
103 int k = i + random_int (3) - 1;
104 double f = factor + random_double (delta) - delta/2.0;
106 if (k < 0) {
107 k = 0;
109 if (k >= width) {
110 k = width - 1;
113 this[i] = (int) (f * last[k]);
114 interpolate_color (output, from, to, this[i]);
115 *cptr++ = output[0];
116 *cptr++ = output[1];
117 *cptr++ = output[2];
118 if (RRGBAFormat==image->format)
119 cptr++;
123 free (this);
124 free (last);
126 return image;