Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CppRaytracer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yoel
CppRaytracer
Commits
422124b7
Commit
422124b7
authored
3 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Halfed is now a function, check if the image is limited before gamma correcting
parent
9a8f4e53
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RayTracer/sampling/Image.cpp
+17
-3
17 additions, 3 deletions
RayTracer/sampling/Image.cpp
RayTracer/sampling/Image.h
+2
-1
2 additions, 1 deletion
RayTracer/sampling/Image.h
with
19 additions
and
4 deletions
RayTracer/sampling/Image.cpp
+
17
−
3
View file @
422124b7
...
...
@@ -9,8 +9,7 @@
#include
"../tools/stb_image.h"
namespace
util
{
Image
::
Image
(
int
width
,
int
height
)
:
width
(
width
),
height
(
height
),
halfed
(
false
)
{
Image
::
Image
(
int
width
,
int
height
)
:
width
(
width
),
height
(
height
)
{
Vec3
color
({});
for
(
int
i
=
0
;
i
<
width
*
height
;
i
++
)
{
vec
.
insert
(
vec
.
end
(),
color
);
...
...
@@ -36,6 +35,9 @@ void Image::setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler) {
}
void
Image
::
gammaCorrect
(
float
gamma
)
{
// Check if the Vec3 in the image are in range [0,1]
std
::
for_each
(
vec
.
begin
(),
vec
.
end
(),
[](
util
::
Vec3
v
)
{
assert
(
v
.
limited
(
0
,
1
));
});
// correct the whole data-array with the given gamma
std
::
transform
(
vec
.
begin
(),
vec
.
end
(),
vec
.
begin
(),
[
gamma
](
util
::
Vec3
v
)
->
util
::
Vec3
{
...
...
@@ -44,6 +46,19 @@ void Image::gammaCorrect(float gamma) {
std
::
powf
(
v
.
z
(),
1
/
gamma
));
});
}
void
Image
::
halfImage
(
bool
upper
,
float
tolerance
)
{
// Half the image
bool
cutter
;
if
(
!
upper
)
tolerance
=
-
tolerance
;
for
(
int
y
=
0
;
y
<
height
;
y
++
)
{
cutter
=
upper
^
(
y
<
(
height
*
(
0.5
+
tolerance
)));
// Color all the x values
for
(
int
x
=
0
;
x
<
width
;
x
++
)
{
if
(
cutter
)
this
->
operator
[]({
x
,
y
})
=
util
::
Vec3
(
0
);
}
}
}
Vec3
Image
::
operator
[](
const
std
::
array
<
int
,
2
>&
i
)
const
{
return
vec
[
width
*
i
[
1
]
+
i
[
0
]];
}
...
...
@@ -52,7 +67,6 @@ Vec3& Image::operator[](const std::array<int, 2>& i) {
}
Vec3
Image
::
color
(
float
x
,
float
y
)
const
{
if
(
halfed
&&
y
>
0.5
)
return
Vec3
(
0
);
int
xx
=
(
int
)((
x
-
std
::
floor
(
x
))
*
width
);
int
yy
=
(
int
)((
y
-
std
::
floor
(
y
))
*
height
);
Vec3
v
=
vec
[
width
*
yy
+
xx
];
...
...
This diff is collapsed.
Click to expand it.
RayTracer/sampling/Image.h
+
2
−
1
View file @
422124b7
...
...
@@ -18,9 +18,10 @@ class Image : public Sampler {
Vec3
color
(
float
x
,
float
y
)
const
override
;
const
int
width
,
height
;
bool
halfed
;
void
gammaCorrect
(
float
gamma
);
void
halfImage
(
bool
upper
,
float
tolerance
);
friend
Image
raytrace
(
size_t
threadcount
,
const
std
::
shared_ptr
<
Scene
>&
scene
,
size_t
n
);
friend
Image
readImage
(
const
char
*
filename
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment