-
Notifications
You must be signed in to change notification settings - Fork 1
/
supersampel.c
128 lines (117 loc) · 3.52 KB
/
supersampel.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* supersampel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mghalmi <mghalmi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/28 11:42:44 by mghalmi #+# #+# */
/* Updated: 2024/02/08 15:50:24 by mghalmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
int supersample_first_corner(int *color, int center, t_rss rss, t_wrapper *w)
{
t_rss tmp;
int *subsquare;
int col;
subsquare = (int *)malloc(sizeof(int) * 4);
if (!subsquare)
error_message("fatal");
subsquare[0] = color[0];
subsquare[1] = calc_ray(1, rss, w);
subsquare[2] = calc_ray(3, rss, w);
subsquare[3] = center;
tmp.limit = rss.limit - 1;
tmp.i = rss.i * 2 - 1;
tmp.j = rss.j * 2 - 1;
tmp.xres = rss.xres * 2;
tmp.yres = rss.yres * 2;
col = supersample(subsquare, tmp, w);
return (col);
}
int supersample_second_corner(int *color, int center, t_rss rss, t_wrapper *w)
{
t_rss tmp;
int *subsquare;
int col;
subsquare = (int *)malloc(sizeof(int) * 4);
if (!subsquare)
error_message("fattal");
subsquare[0] = calc_ray(1, rss, w);
subsquare[1] = color[1];
subsquare[2] = center;
subsquare[3] = calc_ray(5, rss, w);
tmp.limit = rss.limit - 1;
tmp.i = rss.i * 2;
tmp.j = rss.j * 2 - 1;
tmp.xres = rss.xres * 2;
tmp.yres = rss.yres * 2;
col = supersample(subsquare, tmp, w);
return (col);
}
int supersample_third_corner(int *color, int center, t_rss rss, t_wrapper *w)
{
t_rss tmp;
int *subsquare;
int col;
subsquare = (int *)malloc(sizeof(int) * 4);
if (!subsquare)
error_message("fattal");
subsquare[0] = calc_ray(3, rss, w);
subsquare[1] = center;
subsquare[2] = color[2];
subsquare[3] = calc_ray(7, rss, w);
tmp.limit = rss.limit - 1;
tmp.i = rss.i * 2 - 1;
tmp.j = rss.j * 2;
tmp.xres = rss.xres * 2;
tmp.yres = rss.yres * 2;
col = supersample(subsquare, tmp, w);
return (col);
}
int supersample_fourth_corner(int *color, int center, t_rss rss, t_wrapper *w)
{
t_rss tmp;
int *subsquare;
int col;
subsquare = (int *)malloc(sizeof(int) * 4);
if (!subsquare)
error_message("fattal");
subsquare[0] = center;
subsquare[1] = calc_ray(5, rss, w);
subsquare[2] = calc_ray(7, rss, w);
subsquare[3] = color[3];
tmp.limit = rss.limit - 1;
tmp.i = rss.i * 2;
tmp.j = rss.j * 2;
tmp.xres = rss.xres * 2;
tmp.yres = rss.yres * 2;
col = supersample(subsquare, tmp, w);
return (col);
}
int supersample(int *color, t_rss rss, t_wrapper *w)
{
int center;
int n;
center = calc_ray(4, rss, w);
n = 0;
while (n < 4)
{
if (!color_difference(color[n], center) || rss.limit == 0)
color[n] = average(color[n], center);
else
{
if (n == 0)
color[0] = supersample_first_corner(color, center, rss, w);
else if (n == 1)
color[1] = supersample_second_corner(color, center, rss, w);
else if (n == 2)
color[2] = supersample_third_corner(color, center, rss, w);
else
color[3] = supersample_fourth_corner(color, center, rss, w);
}
n++;
}
return (average_supersampled_color(color));
}