-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_pixel.c
113 lines (104 loc) · 3.22 KB
/
sample_pixel.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sample_pixel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mghalmi <mghalmi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/28 11:38:57 by mghalmi #+# #+# */
/* Updated: 2024/01/28 11:40:27 by mghalmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
int *sample_pixel(int *edge_color, int last[2], t_rss rss, t_wrapper *w)
{
int *color;
if (rss.i == 0)
color = sample_first_column(edge_color, last, rss, w);
else if (rss.i == w->data.xres - 1)
color = sample_last_column(edge_color, last, rss, w);
else
color = sample_centered_pixel(edge_color, last, rss, w);
return (color);
}
int *sample_first_column(int *edge_color, int last[2], t_rss rss, t_wrapper *w)
{
int *color;
color = (int *)malloc(sizeof(int) * 4);
if (!color)
error_message("Error malloc failure in sample first column\n");
if (rss.j == w->data.yres / NUM_THREADS * w->tid)
{
color[0] = calc_ray(0, rss, w);
color[1] = calc_ray(2, rss, w);
color[2] = calc_ray(6, rss, w);
color[3] = calc_ray(8, rss, w);
last[0] = color[3];
last[1] = color[1];
edge_color[0] = color[2];
}
else
{
color[0] = edge_color[0];
color[1] = edge_color[1];
color[2] = calc_ray(6, rss, w);
color[3] = calc_ray(8, rss, w);
last[0] = color[3];
edge_color[0] = color[2];
}
return (color);
}
int *sample_last_column(int *edge_color, int last[2], t_rss rss, t_wrapper *w)
{
int *color;
color = (int *)malloc(sizeof(int) * 4);
if (!color)
error_message("Error malloc failure in sample last column\n");
if (rss.j == w->data.yres / NUM_THREADS * w->tid)
{
color[0] = last[1];
color[1] = calc_ray(2, rss, w);
color[2] = last[0];
color[3] = calc_ray(8, rss, w);
edge_color[rss.i] = color[2];
edge_color[rss.i + 1] = color[3];
}
else
{
color[0] = edge_color[rss.i];
color[1] = edge_color[rss.i + 1];
color[2] = last[0];
color[3] = calc_ray(3, rss, w);
edge_color[rss.i] = color[2];
edge_color[rss.i + 1] = color[3];
}
return (color);
}
int *sample_centered_pixel(int *edge_color, int last[2], \
t_rss rss, t_wrapper *w)
{
int *color;
color = (int *)malloc(sizeof(int) * 4);
if (!color)
error_message("Error malloc failure in sample centered pixel\n");
if (rss.j == w->data.yres / NUM_THREADS * w->tid)
{
color[0] = last[1];
color[1] = calc_ray(2, rss, w);
color[2] = last[0];
color[3] = calc_ray(8, rss, w);
last[0] = color[3];
last[1] = color[1];
edge_color[rss.i] = color[2];
}
else
{
color[0] = edge_color[rss.i];
color[1] = edge_color[rss.i + 1];
color[2] = last[0];
color[3] = calc_ray(4, rss, w);
last[0] = color[3];
edge_color[rss.i] = color[2];
}
return (color);
}