-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils.c
69 lines (59 loc) · 1.08 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* EffecTV - Realtime Digital Video Effector
* Copyright (C) 2001-2006 FUKUCHI Kentaro
*
* utils.c: utilities
*
*/
#include <math.h>
#include "EffecTV.h"
#include "utils.h"
int utils_init(void)
{
yuv_init();
if(image_init())
return -1;
return 0;
}
void utils_end(void)
{
image_end();
}
/*
* HSI color system utilities
*/
static int itrunc(double f)
{
int i;
i=(int)f;
if(i<0)i=0;
if(i>255)i=255;
return i;
}
void HSItoRGB(double H, double S, double I, int *r, int *g, int *b)
{
double T,Rv,Gv,Bv;
Rv=1+S*sin(H-2*M_PI/3);
Gv=1+S*sin(H);
Bv=1+S*sin(H+2*M_PI/3);
T=255.999*I/2;
*r=itrunc(Rv*T);
*g=itrunc(Gv*T);
*b=itrunc(Bv*T);
}
/*
* fastrand - fast fake random number generator
* Warning: The low-order bits of numbers generated by fastrand()
* are bad as random numbers. For example, fastrand()%4
* generates 1,2,3,0,1,2,3,0...
* You should use high-order bits.
*/
unsigned int fastrand_val;
unsigned int fastrand(void)
{
return (fastrand_val=fastrand_val*1103515245+12345);
}
void fastsrand(unsigned int seed)
{
fastrand_val = seed;
}