File: utils.c

package info (click to toggle)
effectv 0.3.11-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 748 kB
  • ctags: 1,316
  • sloc: ansic: 12,575; makefile: 216; perl: 38
file content (69 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download
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 trunc_color(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=trunc_color(Rv*T);
	*g=trunc_color(Gv*T);
	*b=trunc_color(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;
}