-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor_tools.c
56 lines (48 loc) · 1.76 KB
/
color_tools.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color_tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: iradchen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/06/15 18:08:10 by iradchen #+# #+# */
/* Updated: 2018/06/15 18:08:11 by iradchen ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf_3d.h"
#define GET_RED(x) (x >> 16)
#define GET_GREEN(x) ((x >> 8) & 0xff)
#define GET_BLUE(x) (x & 0xff)
#define DO_RGB(r, g, b) ((clip(r) << 16) | (clip(g) << 8) | clip(b))
int clip(int color)
{
if (color > 0xff)
return (0xff);
if (color < 0)
return (0);
return (color);
}
void set_pixel(SDL_Surface *surface, int x, int y, Uint32 color)
{
Uint32 *target_pixel;
target_pixel = surface->pixels + y * surface->pitch + \
x * sizeof(Uint32);
*target_pixel = color;
}
Uint32 darker(Uint32 color, double k)
{
Uint8 r;
Uint8 g;
Uint8 b;
r = (Uint8)((double)k * GET_RED(color));
g = (Uint8)((double)k * GET_GREEN(color));
b = (Uint8)((double)k * GET_BLUE(color));
return (DO_RGB(r, g, b));
}
Uint32 get_pixel(SDL_Surface *surface, int x, int y)
{
Uint32 *target_pixel;
target_pixel = surface->pixels + y * surface->pitch + \
x * sizeof(Uint32);
return (*target_pixel);
}