Constness changes
[melted] / src / modules / effectv / utils.c
1 /*
2 * EffecTV - Realtime Digital Video Effector
3 * Copyright (C) 2001-2006 FUKUCHI Kentaro
4 *
5 * utils.c: utilities
6 *
7 */
8
9 #include <math.h>
10 #include "utils.h"
11
12 /*
13 * HSI color system utilities
14 */
15 static int itrunc(double f)
16 {
17 int i;
18
19 i=(int)f;
20 if(i<0)i=0;
21 if(i>255)i=255;
22 return i;
23 }
24
25 void HSItoRGB(double H, double S, double I, int *r, int *g, int *b)
26 {
27 double T,Rv,Gv,Bv;
28
29 Rv=1+S*sin(H-2*M_PI/3);
30 Gv=1+S*sin(H);
31 Bv=1+S*sin(H+2*M_PI/3);
32 T=255.999*I/2;
33 *r=itrunc(Rv*T);
34 *g=itrunc(Gv*T);
35 *b=itrunc(Bv*T);
36 }
37
38 /*
39 * fastrand - fast fake random number generator
40 * Warning: The low-order bits of numbers generated by fastrand()
41 * are bad as random numbers. For example, fastrand()%4
42 * generates 1,2,3,0,1,2,3,0...
43 * You should use high-order bits.
44 */
45 #ifdef __DARWIN__
46 static
47 #endif
48 unsigned int fastrand_val;
49
50 unsigned int fastrand(void)
51 {
52 return (fastrand_val=fastrand_val*1103515245+12345);
53 }
54
55 void fastsrand(unsigned int seed)
56 {
57 fastrand_val = seed;
58 }